Bug 51707 - [c++11] constexpr constructor cannot initialize const reference member
Summary: [c++11] constexpr constructor cannot initialize const reference member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2011-12-30 00:26 UTC by Martin Griffin
Modified: 2014-04-29 16:54 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build: version 4.7.0 20111229 (experimental) (GCC)
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 Martin Griffin 2011-12-30 00:26:06 UTC
====================

struct S {
	constexpr S() {}
};

struct T {
	constexpr T(S const& s) : s{s} {}
	S const& s;
};

constexpr S s {};
constexpr T t { s };

====================

$ g++ -Wall -std=c++11 constexpr_ref_construct.cpp
constexpr_ref_construct.cpp: In constructor ‘constexpr T::T(const S&)’:
constexpr_ref_construct.cpp:6:34: internal compiler error: in build_data_member_initialization, at cp/semantics.c:5788

Curiously everything works fine if instead of struct S we typedef S to be an int (or any other intrinsic type).
Comment 1 Martin von Gagern 2013-02-22 10:32:08 UTC
I get this same error message in a much more complicated situation. I'll simply assume that it's the same thing I'm seeing, but will try to remember running my example through any fix proposed for this issue here.
Comment 2 Paolo Carlini 2014-04-29 16:12:13 UTC
This is fixed in 4.9.0. I'm adding the testcase and closing the bug.
Comment 3 paolo@gcc.gnu.org 2014-04-29 16:53:59 UTC
Author: paolo
Date: Tue Apr 29 16:53:27 2014
New Revision: 209905

URL: http://gcc.gnu.org/viewcvs?rev=209905&root=gcc&view=rev
Log:
2014-04-29  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51707
	* g++.dg/cpp0x/constexpr-51707.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-51707.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2014-04-29 16:54:33 UTC
Done.