2

I am migrating a project from VS 2010 to VS2019. My code is working fine in VS 2010 while I am getting error in VS2019 for the same code.

#undef inline
#define inline __forceinline

..///
..///code 

#undef inline
#define inline inline

Error C1189 #error: The C++ Standard Library forbids macroizing the keyword "inline". Enable warning C4005 to find the forbidden define

How can I remove this error.

Geno C
  • 1,401
  • 3
  • 11
  • 26
user2733061
  • 21
  • 1
  • 5
  • 4
    You can't `#define` a C++ keyword. They are all reserved identifiers. You eliminate the error message by removing `#define inline __forceinline`. – François Andrieux Aug 14 '20 at 18:57
  • 1
    @FrançoisAndrieux I believe the standard says that it's UB to redefine a keyword if you include any standard library headers. It doesn't say it's always UB. That being said, it's pretty hard to not include any standard library headers. – Brian Bi Aug 14 '20 at 18:58
  • @Brian I see questions [like this one](https://stackoverflow.com/questions/9109377/is-it-legal-to-redefine-a-c-keyword) that agree with you, but it dates back to C++11 and [this](https://timsong-cpp.github.io/cppwp/lex.key#1) identifies keywords as reserved while [this](https://timsong-cpp.github.io/cppwp/lex.name#3) forbids the use of reserved identifiers with no conditions on the presence of headers. Is the information in your comment still current? Am I misreading the standard? – François Andrieux Aug 14 '20 at 19:05
  • @FrançoisAndrieux I think that in that context, "identifier" should be read as referring to a type of token. Before translation phase 7, `inline` would only be a preprocessing token, not a token, so the rule would not apply. However I agree the standard is not awfully clear about this. – Brian Bi Aug 14 '20 at 19:09
  • @FrançoisAndrieux The rule about headers is still present [here](http://eel.is/c++draft/macro.names#2). It would be redundant if a general prohibition on redefining keywords existed. – Brian Bi Aug 14 '20 at 19:14
  • @Brian My reading of the linked passage is that keywords are always forbidden from being `#define`d. The condition that a standard header must be included is only included in the first line, which prohibits `#define`ing identifiers declared in standard headers rather than keywords. It would then always be forbidden to `#define inline`. – François Andrieux Aug 14 '20 at 19:18
  • @FrançoisAndrieux But see [this](http://eel.is/c++draft/constraints#overview-1) which seems to limit the scope to "programs that use the facilities of the C++ standard library". – Brian Bi Aug 14 '20 at 19:23
  • @Brian Thanks a lot for the follow up. I didn't know about that section. – François Andrieux Aug 14 '20 at 19:26

2 Answers2

5

I solved it by adding _XKEYCHECK_H to the Properties > C/C++ > Preprocessor > Preprocessor Definitions.
reference: here

enter image description here

Sorry IwontTell
  • 466
  • 10
  • 29
0

I think adding _ALLOW_KEYWORD_MACROS to the preprocessor definition can also solve the problem.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
jackyyin
  • 1
  • 1