tags:

views:

264

answers:

3

It seems to me that this function would not be valid since it uses the keyword 'default' as an identifier:

int foo()
{
    int default = 42;
    return default;
}

However, the Microsoft C++ compiler (versions 14.00.50727.762 and 15.00.30729.0) compile the code without warnings or errors (using the simplest possible command line: 'cl foo.cpp').

Dev-C++ 4.9.9.2 does generate errors when compiling the function.

This seems like such an obvious problem that I must be overlooking something.

Edit: litb dug up the Duplicate for this question Default as a variable name.

+2  A: 

MS Visual C++ 6.0 and g++ 4.4.0 produce numerous errors - as they should. I find it hard to believe that a C++ compiler would accept this - are you sure you really compiled this code?

anon
+1  A: 

default is a reserved word, gcc 4.3.2 won't compile that code, not sure what the MS compiler is playing at there!

Paul Dixon
A: 

No, default is a reserved c++ keyword, that's why its failing to compile.

nmuntz
he is saying that it compiled in MS compiler
TStamper