Compiler Warning (level 1) C4270

nonstandard extension used: 'initializing': a non-const 'type1' must be initialized with an l-value, not a function returning 'type2'

A nonconst reference must be initialized with an l-value, which makes the reference a name for that l-value. A function call is only an l-value if the return type of the function is a reference. A Microsoft extension to the C++ language allows any function call to be treated as an l-value for the purpose of initializing references. If Microsoft extensions are disabled (/Za), then this an error.

This warning can be avoided by ensuring the reference is a const reference. However, if the reference is const and the function return type is not compatible with the type of the reference, the compiler will silently generate and initialize a temporary. Although this is not incorrect, it is inefficient and probably undesirable.

The following example causes this warning:

struct X 
{
   X(int);
   X(X&);
};
X f(X);
X b = f(X(2));   // warning

If you do not have access to source code to fix this problem you can disable this warning using the following pragma:

#pragma warning(disable:4270)