g++ 4.7 evaluates operator “” as sibling to macro expansion

久未见 提交于 2019-12-01 02:48:53

The issue is that "foobar"__TIME__ is no longer tokenized into the preprocessor tokens "foobar" followed by __TIME__.

Preprocessor tokens "have the lexical form of a keyword, an identifier, a literal, an operator, or a punctuator." The addition of user defined literals changes what is lexed as a preprocessor token. Now "foobar"__TIME__ is a single user-defined-character-literal preprocessor token, and so when phase 4 of translation occurs, which would replace __TIME__ with the "15:52:03", there is no __TIME__ token to get replaced this way.

Yes, this behavior is specified in the standard.

Due to the cinttypes macros it looks like more code is affected by this than the committee realized and they are considering addressing it. Some compilers are already moving to handle problems with cinttypes, however not in a way that would fix this use of __TIME__ for you. I think your best bet is to just change the code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!