re PR c++/48089 ([C++0x] ICE on in(?)valid in constexpr constructors)
authorJason Merrill <jason@redhat.com>
Thu, 17 Mar 2011 02:36:29 +0000 (22:36 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 17 Mar 2011 02:36:29 +0000 (22:36 -0400)
PR c++/48089
* semantics.c (potential_constant_expression_1): Don't allow *this
in a constructor.
(register_constexpr_fundef): Use potential_rvalue_constant_expression.

From-SVN: r171086

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C [new file with mode: 0644]

index d96b4b3e31792212f9b12e7d0e4c5fd2aaa57317..7248c119e7b293530eb0413ac6f176f52aa4b402 100644 (file)
@@ -1,5 +1,10 @@
 2011-03-16  Jason Merrill  <jason@redhat.com>
 
+       PR c++/48089
+       * semantics.c (potential_constant_expression_1): Don't allow *this
+       in a constructor.
+       (register_constexpr_fundef): Use potential_rvalue_constant_expression.
+
        PR c++/47301
        * decl.c (compute_array_index_type): Don't bother trying to deal
        with literal classes in ABI v1.
index a0c5ae327a9c34b98c10927fd410663331b38a5e..7519d263f47fd3d2a74eb81f3c5241cb87ea5d3f 100644 (file)
@@ -5674,11 +5674,11 @@ register_constexpr_fundef (tree fun, tree body)
       body = unshare_expr (TREE_OPERAND (body, 0));
     }
 
-  if (!potential_constant_expression (body))
+  if (!potential_rvalue_constant_expression (body))
     {
       DECL_DECLARED_CONSTEXPR_P (fun) = false;
       if (!DECL_TEMPLATE_INSTANTIATION (fun))
-       require_potential_constant_expression (body);
+       require_potential_rvalue_constant_expression (body);
       return NULL;
     }
   fundef->body = body;
@@ -7496,7 +7496,16 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
         tree x = TREE_OPERAND (t, 0);
         STRIP_NOPS (x);
         if (is_this_parameter (x))
-         return true;
+         {
+           if (DECL_CONSTRUCTOR_P (DECL_CONTEXT (x)) && want_rval)
+             {
+               if (flags & tf_error)
+                 error ("the value of the object being constructed is "
+                        "not a constant expression");
+               return false;
+             }
+           return true;
+         }
        return potential_constant_expression_1 (x, rval, flags);
       }
 
index bf17d3d7e5dbc01803f550bfb89e9c915afef4b3..b05752483d666e391cdb182356b0a56e85985d8c 100644 (file)
@@ -1,5 +1,7 @@
 2011-03-16  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/constexpr-48089.C: New.
+
        * g++.dg/cpp0x/constexpr-abi1.C: New.
 
        * g++.dg/cpp0x/constexpr-46336.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C
new file mode 100644 (file)
index 0000000..88ef3d6
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/48089
+// { dg-options -std=c++0x }
+
+struct s {
+    constexpr s() : v(v) { }   // { dg-error "object being constructed" }
+    char v;
+};
+
+s bang;