From 70fc7c6c3dff619348c917b619bf52ac78a6ced1 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 13 Feb 2013 12:56:38 -0500 Subject: [PATCH] re PR c++/55879 ([C++11] nested constexpr Initialisation raises internal compiler error) PR c++/55879 * semantics.c (cxx_bind_parameters_in_call): Undo DECL_BY_REFERENCE. From-SVN: r196024 --- gcc/cp/ChangeLog | 3 ++ gcc/cp/semantics.c | 9 +++++ .../g++.dg/cpp0x/constexpr-invisiref1.C | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-invisiref1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 977d2458663..ec1e7f20628 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2013-02-13 Jason Merrill + PR c++/55879 + * semantics.c (cxx_bind_parameters_in_call): Undo DECL_BY_REFERENCE. + PR c++/55993 * semantics.c (cxx_fold_indirect_ref): Handle empty bases at non-zero offsets, too. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 30c8c522f24..46c2e643806 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6520,6 +6520,15 @@ cxx_bind_parameters_in_call (const constexpr_call *old_call, tree t, if (i == 0 && DECL_CONSTRUCTOR_P (fun)) goto next; x = get_nth_callarg (t, i); + if (parms && DECL_BY_REFERENCE (parms)) + { + /* cp_genericize made this a reference for argument passing, but + we don't want to treat it like one for constexpr evaluation. */ + gcc_assert (TREE_CODE (type) == REFERENCE_TYPE); + gcc_assert (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE); + type = TREE_TYPE (type); + x = convert_from_reference (x); + } arg = cxx_eval_constant_expression (old_call, x, allow_non_constant, TREE_CODE (type) == REFERENCE_TYPE, non_constant_p, overflow_p); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-invisiref1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-invisiref1.C new file mode 100644 index 00000000000..e0ede738a40 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-invisiref1.C @@ -0,0 +1,36 @@ +// PR c++/55879 +// { dg-do compile { target c++11 } } + +class CAddress +{ +public: + constexpr CAddress(unsigned long begin) : m_Begin(begin) {} + constexpr CAddress(const CAddress &other) : m_Begin(other.m_Begin) {} + +private: + unsigned long m_Begin; +}; + +extern "C" char _lnkDDRRAM; +/* internal compiler error on gcc 4.6.3 */ +const CAddress s_Memmap[2] +{ + {(unsigned long)&_lnkDDRRAM}, /* segmentation fault */ + {0x40000000}, +}; + +class CNested { +public: + constexpr CNested(const CAddress primary) + : m_PrimaryBlock(primary) {} + +private: + CAddress m_PrimaryBlock; +}; + +/* internal compiler error on gcc 4.7.2 */ +const CNested s_taskDescriptions[2] +{ + {{0x42000000}}, + {{0x43000000}}, +};