aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl2.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-02-21 10:35:44 -0500
committerJason Merrill <jason@gcc.gnu.org>2011-02-21 10:35:44 -0500
commit9931a2bf8c807326be1596dc0698872e32823e17 (patch)
treeb4c3ba53f68b6d7631c54b3b504bd02dcf9ce100 /gcc/cp/decl2.c
parente292d00367ce0a736a7c1e1433e7920eeb0673cf (diff)
downloadgcc-9931a2bf8c807326be1596dc0698872e32823e17.zip
gcc-9931a2bf8c807326be1596dc0698872e32823e17.tar.gz
gcc-9931a2bf8c807326be1596dc0698872e32823e17.tar.bz2
re PR c++/47207 ([C++0x] ICE: in decl_constant_var_p, at cp/decl2.c:3563 on invalid code)
PR c++/47207 * decl2.c (decl_constant_var_p): A constexpr var needs an initializer to be constant. * semantics.c (cxx_eval_constant_expression): Complain about constexpr var used in its own initializer. * call.c (set_up_extended_ref_temp): Set DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P too. From-SVN: r170365
Diffstat (limited to 'gcc/cp/decl2.c')
-rw-r--r--gcc/cp/decl2.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index a4b7dfa..93d44a4 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -3550,20 +3550,21 @@ decl_constant_var_p (tree decl)
tree type = TREE_TYPE (decl);
if (TREE_CODE (decl) != VAR_DECL)
return false;
- if (DECL_DECLARED_CONSTEXPR_P (decl))
- ret = true;
- else if (CP_TYPE_CONST_NON_VOLATILE_P (type)
- && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
+ if (DECL_DECLARED_CONSTEXPR_P (decl)
+ || (CP_TYPE_CONST_NON_VOLATILE_P (type)
+ && INTEGRAL_OR_ENUMERATION_TYPE_P (type)))
{
/* We don't know if a template static data member is initialized with
- a constant expression until we instantiate its initializer. */
+ a constant expression until we instantiate its initializer. Even
+ in the case of a constexpr variable, we can't treat it as a
+ constant until its initializer is complete in case it's used in
+ its own initializer. */
mark_used (decl);
ret = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl);
}
else
ret = false;
- gcc_assert (!ret || DECL_INITIAL (decl));
return ret;
}