Bug 58977 - C++11 uniform initialization syntax causes error
Summary: C++11 uniform initialization syntax causes error
Status: RESOLVED DUPLICATE of bug 50025
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-03 01:52 UTC by DrTwox
Modified: 2013-11-03 12:20 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***