Bug 58977

Summary: C++11 uniform initialization syntax causes error
Product: gcc Reporter: DrTwox <drtwox>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P3    
Version: 4.8.1   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description DrTwox 2013-11-03 01:52:11 UTC
Code example and compiler output explains all:

#include <fstream>

struct foo
{
    foo( std::fstream& stream )
        : stream_{ stream } // <-- Here's the problem
    {}

    std::fstream& stream_;
};

int main()
{
    std::fstream stream;
    foo f{ stream };
}


$ g++ --version
g++ (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1

$ g++ brace.cpp -std=c++11 -Wall -Wextra
brace.cpp: In constructor ‘foo::foo(std::fstream&)’:                                                                                               
brace.cpp:6:21: error: invalid initialization of non-const reference of type ‘std::fstream& {aka std::basic_fstream<char>&}’ from an rvalue of type ‘<brace-enclosed initializer list>’                                                                                                               
   : stream_{ stream } // <-- Here's the problem
Comment 1 Jonathan Wakely 2013-11-03 11:33:41 UTC
I think this is http://www.open-std.org/Jtc1/sc22/wg21/docs/cwg_defects.html#1288 which makes this a duplicate of PR 50025
Comment 2 Paolo Carlini 2013-11-03 12:20:21 UTC
Dup.

*** This bug has been marked as a duplicate of bug 50025 ***