Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:14:00+00:00 2026-05-27T22:14:00+00:00

EDIT: GCC compiles it just fine, it’s VS2010 issue. Thanks for pointing me to

  • 0

EDIT: GCC compiles it just fine, it’s VS2010 issue. Thanks for pointing me to ideone.com!

While trying to compile the following (VS2010):

#include <iostream>

template< typename PF01, typename PF02 >
inline auto FCall01( PF01 fCallee, PF02 && fParameter00 ) -> decltype( fCallee( std::forward< PF02 > ( fParameter00 ) ) )
{
 decltype( fCallee( std::forward< PF02 > ( fParameter00 ) ) ) lResult( fCallee( std::forward< PF02 >( fParameter00 ) ) ); // offending line for Foo03

 return ( lResult );
}

int gI = 0;
int & gCI = gI;

struct TA
{
  int mData;
  TA( int fData = 0 ) : mData( fData ) { }
  TA( TA const & fA ) : mData( fA.mData ) { }
};

int Foo00( int & fA ){ return ( fA ); }
int & Foo01( int & ){ return ( gCI ); }
int const & Foo02( int & ){ return ( gCI ); }
TA Foo03( int & fA ){ return ( TA( fA ) ); }

int main( void )
{
  decltype( FCall01( Foo00, gI ) ) l0( FCall01( Foo00, gI ) );
  l0 = -1;
  std::cout << gI << " : " << l0 << std::endl;

  decltype( FCall01( Foo01, gI ) ) l1( FCall01( Foo01, gI ) );
  l1 = -2;
  std::cout << gI << " : " << l1 << std::endl;

  decltype( FCall01( Foo02, gI ) ) l2( FCall01( Foo02, gI ) );
  const_cast< int & > ( l2 ) = -3;
  std::cout << gI << " : " << l2 << std::endl;

  decltype( FCall01( Foo03, gI ) ) l3( FCall01( Foo03, gI ) );
  l3.mData = -4;
  std::cout << gI << " : " << l3.mData << std::endl;

  return ( 0 );
}

I get a compiler warning:

Warning C4239: nonstandard extension used : 'initializing' : conversion from 'TA' to
'TA &'; A non-const reference may only be bound to an lvalue; see reference to function
template instantiation 'TA &FCall01<TA(__cdecl *)(int &),int&>(PF01,PF02) with
[PF01=TA(__cdecl *)(int &),PF02=int &]' being compiled.

Everything is fine for built-in type, but for user-defined type, decltype(...) in the template function FCall gives me TA& instead of TA, both as FCall return type and local variable in FCall.

I don’t see logic behind it, and I think Standard says decltype(f()) should give exactly return type of f(). And it works fine for built-in types. Is there some hidden catch for user-defined types or it’s just VS2010 playing tricks on me?

P.S. I don’t have access to GCC, could someone, please, check if GCC compiles is it without warnings?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:14:00+00:00Added an answer on May 27, 2026 at 10:14 pm

    It’s a compiler bug in VS2010. It does not happen in neither GCC (ideone.com) nor Visual C++ 11 Developer Preview.

    Thanks to PlasmaHH and Xeo for the link to ideone.com, and Jesse for the info on the bug status in Visual C++ 11 Developer Preview.

    EDIT: Just a follow-up: this bug in VS2010 happens when user-defined type has user-defined constructor. If it does not have one (compiler generated default is used), bug does not happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just realised that this program compiles and runs (gcc version 4.4.5 / Ubuntu):
EDIT Thanks to all for your input. I guess my question was just a
I've got a standard C library that compiles just fine on Mac OS X
The following snippet fails to compile with Visual Studio 2010, but GCC likes it:
We are using a legacy compiler, based on gcc 2.6.0, to cross compile for
I'm using MinGw on Windows 7. The following simple program compiles fine, but the
My iPhone app was compiling just fine, then all of the sudden, it started
I am trying to use the GCC pragma optimize to set global optimizations in
We just upgraded our compiler to gcc 4.6 and now we get some of
I'm having trouble deciding whether not this code should compile or if just both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.