为什么这个看起来无效的代码在g ++ 6.0上成功编译? [英] Why does this invalid-looking code compile successfully on g++ 6.0?
问题描述
考虑这个奇怪的程序:
int main()
{
int(*){} Is it C++14 or any other language?
}
(See a live demo here & here.)
即使 //
缺失,代码编译正常,没有任何错误&即使我在g ++ 6.0中使用 -pedantic-errors
选项也会出现警告。这似乎是一个编译器bug给我。这是编译器真的是一个错误吗?
Even though the comment //
is missing, the code compiles fine without any errors & warnings even when I use -pedantic-errors
options in g++ 6.0. This seems like a compiler bug to me. Is it really a bug in the compiler?
推荐答案
这看起来是一个bug /功能/版本我可以测试它。正在运行
This looks to be an bug/feature/issue with g++ in all of the versions I can test it on. Running
int main()
{
int(*){} Is it C++14 or any other language?
}
在 godbolt.org 的所有版本的g ++没有编译标志给出以下程序集输出。
On godbolt.org for all versions of g++ with no compilation flags give the following assembly ouput.
main:
pushq %rbp
movq %rsp, %rbp
movl $0, %eax
leave
ret
我得到的唯一诊断是在 godbolt.org ,这是
The only diagnosis I get is on godbolt.org and that is
!!warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
Clang,ICC和MSVS都无法编译。
Clang, ICC and MSVS all fail to compile this.
编辑:
在 zwol 提交的评论中bug与gcc上这个。可以在此处找到错误报告。
From the comments zwol filed a bug with gcc on this. The bug report can be found here.
这篇关于为什么这个看起来无效的代码在g ++ 6.0上成功编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!