re PR c++/48993 ([C++0x] segmentation fault when compiling this program with constexpr)
authorJason Merrill <jason@redhat.com>
Sat, 6 Aug 2011 04:34:45 +0000 (00:34 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 6 Aug 2011 04:34:45 +0000 (00:34 -0400)
PR c++/48993
* semantics.c (potential_constant_expression_1) [CALL_EXPR]: Sorry
on 'this' in a constructor.

From-SVN: r177499

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C

index 18bf49385ed987bb4dd61ce6cba0de777be32639..81c1d923e9ba3f7624de17d99b4b1572a7819807 100644 (file)
@@ -1,5 +1,9 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       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.
 
index 3d836eb56c79564887eae51ec2ba377d66e9b4ca..aa62049f8be93b3b70ed26b9cd2b409bc34c3800 100644 (file)
@@ -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;
index cef7f415a193ba2bd71ffdf282a305b5f745eaf5..bdfacbf796ea147b4f6d251b96beadee07f6834c 100644 (file)
@@ -1,5 +1,8 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/48993
+       * g++.dg/cpp0x/constexpr-48089.C: Add cases.
+
        PR c++/49921
        * g++.dg/cpp0x/decltype31.C: New.
 
index fc69cfef6780d1f352c45bdd2c5ae91cb7261948..5124f7c7f4982d0c8996e7555aa1533bab7c9f8b 100644 (file)
@@ -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 *-*-* } }