Is there a valid C++11 program with the expression 'C++11'?
c++, c++11
Solution
NO if we require the characters `C++11` to be outside any literal, after preprocessing -- because at translation phase 7 the three tokens will be `identifier`, `++` and `integer-literal`
The first two tokens are a `postfix-expression`, the later is a `primary`.
There is no reduction in the grammar that can contain these two nonterminals in sequence, so any program containing `C++11` will fail syntax analysis.
However, if you do not consider character literals to be strings, then the answer is YES as you can contain it in a wide character literal:
int main()
{
wchar_t x = L'C++11';
}
which does not use the preprocessor or a string literal, and the construct is required to be supported by the standard:
The value of a wide-character literal containing multiple c-chars is implementation-defined.
Problem
The name of the programming language C++ derives from the parent language C and the ++ operator (it should arguably be ++C) and, hence, the expression `C++` may naturally occur in C++ programs. I was wondering whether you can write a valid C++ program using the 2011 standard (without extensions) and containing the expression `C++11` not within quotes and after pre-processing (note: edited the requirement, see also answer). Obviously, if you could write a C++ program prior to the 2011 standard with the expressions `C++98` or `C++03`, then the answer is a trivial yes. But I don't think that was possible (though I don't really know). So, can it be done with the new armory of C++11?