1

I'm migrating existing project to VS2019. Having very simple structure that successfully compiled in all previous versions:

template <class Marker>
struct not
{
    // ...

error C2332: 'struct': missing tag name

NOTE-1 I've checked by pre-compilatinion generation that not is not substituted with some macros, output of *.i file fully matches declaration above

NOTE-2 of course if I rename not->inv then all everything is right

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • Check http://eel.is/c++draft/lex.key#2: _the alternative representation `not` is reserved and shall not be used otherwise_. – Daniel Langr Feb 17 '20 at 14:40
  • 1
    `not` is a keyword in C and C++ https://en.cppreference.com/w/cpp/language/operator_alternative, it is strange that it worked before – RoQuOTriX Feb 17 '20 at 14:40
  • 4
    @RoQuOTriX: indeed. The question should not be "Why does this give an error now?" but "Why did this not give an error before?". – Dominique Feb 17 '20 at 14:41
  • @Dewfy check this out for more info - https://stackoverflow.com/questions/2376448/the-written-versions-of-the-logical-operators – rootkonda Feb 17 '20 at 14:47
  • @walnut - please make it as an answer - since you the only one who get a point "how to resolve". Thanks! – Dewfy Feb 17 '20 at 14:48

3 Answers3

5

not is a keyword in C++, it cannot be used as class name.

See list of keywords on cppreference.

Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52
5

not is an alternative operator for !, i.e. a C++ keyword and, thus, it cannot be used in naming.

See the docs.

NutCracker
  • 11,485
  • 4
  • 44
  • 68
3

not is a keyword in standard C++ which can be used as alternative for the ! token.

MSVC does not support the alternative operator tokens by default. Therefore they are available as identifiers and you don't get an error on your declaration.

But in compliance mode with the /permissive- compiler flag, these tokens are considered keywords with their standard meaning and so they are not available as identifiers.

I suggest not using not as identifier, even when not using compliance mode, because that makes your code non-standard and non-portable.

see https://learn.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance

and Why does VS not define the alternative tokens for logical operators?

walnut
  • 21,629
  • 4
  • 23
  • 59