It is also the case that using 'this' in a non-constexpr function should
prevent the expression from being constant.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit e0f26a1998f2cb404e58bcf8a9f22e29401312e0
Author: Jason Merrill <ja...@redhat.com>
Date: Thu Feb 28 11:58:44 2013 -0500
PR c++/56481
* semantics.c (potential_constant_expression_1): Use of 'this' in
a non-constexpr function makes the expression not potentially
constant.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 1cf060e..9d2f3f4 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -8497,6 +8497,13 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
STRIP_NOPS (x);
if (is_this_parameter (x))
{
+ if (DECL_CONTEXT (x)
+ && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
+ {
+ if (flags & tf_error)
+ error ("use of %<this%> in a constant expression");
+ return false;
+ }
if (want_rval && DECL_CONTEXT (x)
&& DECL_CONSTRUCTOR_P (DECL_CONTEXT (x)))
{