From b569be8ca62060f697f5a90a7933d880f334ace6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 6 Aug 2011 00:34:45 -0400 Subject: [PATCH] re PR c++/48993 ([C++0x] segmentation fault when compiling this program with constexpr) PR c++/48993 * semantics.c (potential_constant_expression_1) [CALL_EXPR]: Sorry on 'this' in a constructor. From-SVN: r177499 --- gcc/cp/ChangeLog | 4 +++ gcc/cp/semantics.c | 12 ++++++++- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C | 26 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 18bf49385ed..81c1d923e9b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2011-08-05 Jason Merrill + PR c++/48993 + * semantics.c (potential_constant_expression_1) [CALL_EXPR]: Sorry + on 'this' in a constructor. + PR c++/49921 * semantics.c (finish_decltype_type): Call invalid_nonstatic_memfn_p. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 3d836eb56c7..aa62049f8be 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7733,7 +7733,17 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags) { tree x = get_nth_callarg (t, 0); if (is_this_parameter (x)) - /* OK. */; + { + if (DECL_CONSTRUCTOR_P (DECL_CONTEXT (x))) + { + if (flags & tf_error) + sorry ("calling a member function of the " + "object being constructed in a constant " + "expression"); + return false; + } + /* Otherwise OK. */; + } else if (!potential_constant_expression_1 (x, rval, flags)) return false; i = 1; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cef7f415a19..bdfacbf796e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2011-08-05 Jason Merrill + PR c++/48993 + * g++.dg/cpp0x/constexpr-48089.C: Add cases. + PR c++/49921 * g++.dg/cpp0x/decltype31.C: New. diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C index fc69cfef678..5124f7c7f49 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C @@ -22,3 +22,29 @@ struct R { }; constexpr R r; // { dg-bogus "" "" { xfail *-*-* } } + +// Ill-formed (no diagnostic required) +struct T { + int i; + constexpr int f() { return i; } + constexpr T(): i(0) { } + constexpr T(const T& t) : i(f()) { } // { dg-message "" } +}; + +constexpr T t1; +// Ill-formed (diagnostic required) +constexpr T t2(t1); // { dg-error "" } + +// Well-formed +struct U { + int i, j; + constexpr int f(int _i) { return _i; } + constexpr int g() { return i; } + constexpr U(): i(0), j(0) { } + constexpr U(const U& t) : i(f(t.i)),j(0) { } // { dg-bogus "" "" { xfail *-*-* } } + constexpr U(int _i) : i(_i),j(g()) { } // { dg-bogus "" "" { xfail *-*-* } } +}; + +constexpr U u1; +constexpr U u2(u1); // { dg-bogus "" "" { xfail *-*-* } } +constexpr U u3(1); // { dg-bogus "" "" { xfail *-*-* } } -- 2.30.2