aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-03-16 22:36:29 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-03-16 22:36:29 -0400
commitcb21e9cdf7176be9c23c3a003822cf7a3d3f4995 (patch)
tree428b8802ef5eb5969169de941eb45a54c6b502c1 /gcc
parent89ae3825aa6e60bb68010353f2a292a056b8a9da (diff)
downloadgcc-cb21e9cdf7176be9c23c3a003822cf7a3d3f4995.zip
gcc-cb21e9cdf7176be9c23c3a003822cf7a3d3f4995.tar.gz
gcc-cb21e9cdf7176be9c23c3a003822cf7a3d3f4995.tar.bz2
re PR c++/48089 ([C++0x] ICE on in(?)valid in constexpr constructors)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/semantics.c15
-rw-r--r--gcc/testsuite/ChangeLog2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C9
4 files changed, 28 insertions, 3 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index d96b4b3..7248c11 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index a0c5ae3..7519d26 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bf17d3d..b057524 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..88ef3d6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-48089.C
@@ -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;