为什么这个看起来无效的代码在g ++ 6.0上编译成功?

考虑一下这个奇怪的程序:

int main() { int(*){} Is it C++14 or any other language? } 

( 在这里和这里看到一个现场演示。)

即使注释//缺失,即使在g ++ 6.0中使用-pedantic-errors选项代码也能正常编译,不会出现任何错误和警告。 这对我来说似乎是一个编译器错误。 它真的是编译器中的错误吗?

这看起来是所有我可以testing的版本中的g ++的bug /function/问题。 运行

 int main() { int(*){} Is it C++14 or any other language? } 

在godbolt.org的所有版本的g ++没有编译标志给出下面的程序集输出。

 main: pushq %rbp movq %rsp, %rbp movl $0, %eax leave ret 

我得到的唯一诊断是在godbolt.org上

 !!warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x 

铛,ICC和MSVS都没有编译这个。

编辑:

从评论zwol提交了一个gcc的错误在这个。 错误报告可以在这里find。

我使用g++ version 5.1.1在Fedora VM上运行这个命令,发现如下:

 [user:~] 1 $ g++ -fdump-tree-original-raw tmp.cpp tmp.cpp: In function 'int main()': tmp.cpp:3:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 int(*){} Is it C++14 or any other language? ^ 

然而,仍然设法编译…所以我已经倾销AST并得到这个:

 $ cat tmp.cpp.003t.original ;; Function int main() (null) ;; enabled by -tree-original @1 return_expr type: @2 expr: @3 @2 void_type name: @4 algn: 8 @3 init_expr type: @5 op 0: @6 op 1: @7 @4 type_decl name: @8 type: @2 srcp: <built-in>:0 note: artificial @5 integer_type name: @9 size: @10 algn: 32 prec: 32 sign: signed min : @11 max : @12 @6 result_decl type: @5 scpe: @13 srcp: tmp.cpp:1 note: artificial size: @10 algn: 32 @7 integer_cst type: @5 int: 0 @8 identifier_node strg: void lngt: 4 @9 type_decl name: @14 type: @5 srcp: <built-in>:0 note: artificial @10 integer_cst type: @15 int: 32 @11 integer_cst type: @5 int: -2147483648 @12 integer_cst type: @5 int: 2147483647 @13 function_decl name: @16 type: @17 scpe: @18 srcp: tmp.cpp:1 lang: C link: extern @14 identifier_node strg: int lngt: 3 @15 integer_type name: @19 size: @20 algn: 128 prec: 128 sign: unsigned min : @21 max : @22 @16 identifier_node strg: main lngt: 4 @17 function_type size: @23 algn: 8 retn: @5 prms: @24 @18 translation_unit_decl @19 identifier_node strg: bitsizetype lngt: 11 @20 integer_cst type: @15 int: 128 @21 integer_cst type: @15 int: 0 @22 integer_cst type: @15 int: -1 @23 integer_cst type: @15 int: 8 @24 tree_list valu: @2 

这太大了,不适合评论,但应该有助于确定发生了什么事情。 我仍然经历这个,但我只是发布这个信息,为他人build立。

这是可视化的 在这里输入图像说明