This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH for c++/56481 (time hog with repeated &&)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 16 Mar 2013 21:34:38 -0400
- Subject: Re: C++ PATCH for c++/56481 (time hog with repeated &&)
- References: <512FBC23.5030507@redhat.com>
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 <jason@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)))
{