C++ 为什么要从预处理的C++;源代码使它无法编译? 例子
一切正常 让我们删除行信息,如下所示:C++ 为什么要从预处理的C++;源代码使它无法编译? 例子,c++,compiler-errors,c-preprocessor,C++,Compiler Errors,C Preprocessor,一切正常 让我们删除行信息,如下所示: # 1 "somefile.cpp" # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 380 "<built-in>" 3 # 1 "<command line>" 1 # 1 "<built-in>" 2 # 1 "somefile.cpp" 2 # 1 "../someheader.h" 1 # 1 "/usr/include/clang/8.0.1/inclu
# 1 "somefile.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 380 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "somefile.cpp" 2
# 1 "../someheader.h" 1
# 1 "/usr/include/clang/8.0.1/include/stdint.h" 1 3
# 61 "/usr/include/clang/8.0.1/include/stdint.h" 3
# 1 "/usr/include/stdint.h" 1 3 4
问题:
为什么删除应该只影响来自编译器的消息的信息实际上会影响编译结果?这里有一些信息可以帮助您理解原因。当所有警告都打开时,许多系统头文件将无法编译,并且是致命的(gcc的
-Wall-Werror
)。因此,预处理器会标记来自头文件的代码,因此编译器可以关闭此功能。这里也发生了类似的事情。@SamVarshavchik,#pragma
s是正则表达式允许的。在qq.e
中有各种#pragma GCC diagnostic ignored
。我所指的特定功能不使用pragma。专业提示:上面显示的文件+行指令是否有额外的内容?您是否曾经想过,在通知您编译已切换到stdint.h的第1行时,额外的“3”在那里做什么?这实际上是在pubilc gcc文档中记录的,我前几天发现的。
# 1 "somefile.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 380 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "somefile.cpp" 2
# 1 "../someheader.h" 1
# 1 "/usr/include/clang/8.0.1/include/stdint.h" 1 3
# 61 "/usr/include/clang/8.0.1/include/stdint.h" 3
# 1 "/usr/include/stdint.h" 1 3 4
cat q.e | grep -v '^# ' > qq.e
clang++-8 -std=c++11 -x c++ qq.e -c -o q.o
qq.e:238:20: warning: '__format__' attribute argument not supported: gnu_printf [-Wignored-attributes]
__attribute__((__format__(__gnu_printf__, 1, 2)));
^
qq.e:311:12: warning: keyword '__is_void' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
struct __is_void
(many more warnings)
qq.e:36194:3: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
acos(float __x)
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]