考虑一下这个无害的C++程序:
#include <iostream>
int main() {
std::cout << "(Is this a trigraph??)" << std::endl;
return 0;
}当我使用g++版本5.4.0编译它时,我得到以下诊断:
me@my-laptop:~/code/C++$ g++ -c test_trigraph.cpp
test_trigraph.cpp:4:36: warning: trigraph ??) ignored, use -trigraphs to enable [-Wtrigraphs]
std::cout << "(Is this a trigraph??)" << std::endl;
^该程序正在运行,其输出与预期的相同:
(Is this a trigraph??)为什么字符串文字会被解析成三角图呢?
其他编译器也会这么做吗?
发布于 2017-12-20 10:52:34
曲线图是在翻译阶段1处理的(然而,它们在C++17中被删除)。字符串文字相关的处理发生在后续阶段。正如C++14标准指定的(n4140) [lex.phases]/1.1
翻译的语法规则之间的优先级由以下阶段指定。
这是首先发生的,因为正如你在评论中被告知的那样,曲线图所代表的字符也必须是可打印的。
https://stackoverflow.com/questions/47904259
复制相似问题