为什么这个代码片段使用统一初始化编译g ++ 4.6但不是g ++ 4.7? [英] Why does this snippet using uniform initialization compile with g++4.6 but not g++4.7?

查看:150
本文介绍了为什么这个代码片段使用统一初始化编译g ++ 4.6但不是g ++ 4.7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意,派生使用C ++ 11统一初始化语法来调用基类构造函数。

Note that derived uses C++11 uniform initialization syntax to call the base class constructor.

class base
{
    protected:
        base()
        {}
};

class derived : public base
{
    public:
        derived()
            : base{} // <-- Note the c++11 curly brace syntax
                     // using uniform initialization. Change the
                     // braces to () and it works.
        {}
};

int main()
{
    derived d1;

    return 0;
}

g ++ 4.6编译这个,但g ++ 4.7不: / p>

g++4.6 compiles this, however g++4.7 does not:

$ g++-4.7 -std=c++11 -Wall -Wextra -pedantic curly.cpp -o curly
curly.cpp: In constructor ‘derived::derived()’:
curly.cpp:4:13: error: ‘base::base()’ is protected
curly.cpp:19:24: error: within this context

发生了什么事?

更新1:它也使用clang ++编译没有警告 - 3.1

更新2:

Update 1: It also compiles without warnings with clang++-3.1
Update 2: Looks like a compiler bug for sure. It's apparently fixed in GCC 4.7.3.

推荐答案

Paolo Carlini,一个GCC / libstdc ++参与者,确认这是一个错误/回归

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

这篇关于为什么这个代码片段使用统一初始化编译g ++ 4.6但不是g ++ 4.7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆