考虑这个奇怪的程序:
int main()
{
int(*){} Is it C++14 or any other language?
}
Run Code Online (Sandbox Code Playgroud)
即使//缺少注释,即使我-pedantic-errors在g ++ 6.0中使用选项,代码编译也没有任何错误和警告.这对我来说似乎是一个编译器错误.它真的是编译器中的错误吗?
Nat*_*ica 42
这看起来是我可以在其上测试的所有版本中使用g ++的bug /功能/问题.运行
int main()
{
int(*){} Is it C++14 or any other language?
}
Run Code Online (Sandbox Code Playgroud)
在godbolt.org上,没有编译标志的所有g ++版本都提供以下程序集输出.
main:
pushq %rbp
movq %rsp, %rbp
movl $0, %eax
leave
ret
Run Code Online (Sandbox Code Playgroud)
我得到的唯一诊断是在godbolt.org上,就是这样
!!warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
Run Code Online (Sandbox Code Playgroud)
Clang,ICC和MSVS都无法编译.
编辑:
从评论zwol提交了一个关于gcc的错误.错误报告可以在这里找到.
non*_*kle 15
我已经在我的Fedora的VM运行该命令g++的版本5.1.1,发现如下:
[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?
^
Run Code Online (Sandbox Code Playgroud)
然而,仍然设法编译......所以我抛弃了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
Run Code Online (Sandbox Code Playgroud)
哪个太大而不适合评论,但应该有助于确定发生了什么.我仍然会经历这个,但我只是发布这些信息供其他人构建.
| 归档时间: |
|
| 查看次数: |
3485 次 |
| 最近记录: |