Why does this snippet using uniform initialization compile with g++4.6 but not g++4.7?

*爱你&永不变心* 提交于 2019-12-03 00:55:22

Paolo Carlini, a GCC/libstdc++ contributor, confirmed it is a bug/regression.

It is probably because in version 4.7 C11 explicit override control was added.

compiling this with icpc ( intel compiler tested with version 11.1 -> 12.1) gives:

-bash-3.2$ icpc -std=c++0x test.c 
test.c(15): error: expected a declaration
          {}
          ^

test.c(12): error: expected a "("
              : base{} // <-- Note the c++11 curly brace syntax
                    ^

compilation aborted for test.c (code 2)

edit: but then again, c++11 is not fully implemented yet in icpc either http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler/

same as with g++ http://gcc.gnu.org/gcc-4.7/cxx0x_status.html

which clearly states it's still experimental, so a bug is very likely.

I found this:

"The draft says that an initializer list initializing a reference is done not by direct binding, but by first constructing a temporary out of the element in the initializer list, and then binding the target reference to that temporary"

So it might be choking on the fact that the temporary created by base{} is being done through a protected constructor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!