C++ – Disable GCC Warning About Missing Underscore in User Defined Literal

c++c++11user-defined-literals

void operator"" test( const char* str, size_t sz  )
{
    std::cout<<str<<" world";
}

int main()
{
    "hello"test;
    return 0;
}

In GCC 4.7, this generates "warning: literal operator suffixes not preceded by '_' are reserved for future standardization [enabled by default]"

I understand why this warning is generated, but GCC says "enabled by default".

Is it possible to disable this warning without just disabling all warnings via the -w flag?

Best Answer

After reading several comments to this question, I reviewed the C++ 11 Standard (non-final draft N3337).

When I said "I understand why this warning is generated" I was mistaken. I assumed that an underscore was not technically required by the standard, but just a recommendation (hence the warning rather than an error).

But as Nicol Bolas has brought up, the standard uses the following language when speaking about user defined literals:

"Literal suffix identifiers that do not start with an underscore are reserved for future standardization." usrlit.suffix

"Some literal suffix identifiers are reserved for future standardization; see [usrlit.suffix]. A declaration whose literal-operator-id uses such a literal suffix identifier is ill-formed, no diagnostic required." over.literal

This is similar to the language used for reserved identifiers and the "alternative representations" such as "and", "or", "not". I think this makes it pretty clear that this shouldn't actually be a warning in the first place, but an error.

This may not be the direct answer to the question of "is it possible to disable", but it is answer enough for me.