aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-10-29 15:19:51 -0400
committerMarek Polacek <polacek@redhat.com>2020-11-03 10:09:53 -0500
commitc2856ceec2e7542fe9b0bf104afeeeeb57d6996d (patch)
tree028f74c4d0f6294d8f0d52ae0fed7a136fda09a9 /gcc
parentf620e64a6f13371b95be5b17abba0acf15bf7cae (diff)
downloadgcc-c2856ceec2e7542fe9b0bf104afeeeeb57d6996d.zip
gcc-c2856ceec2e7542fe9b0bf104afeeeeb57d6996d.tar.gz
gcc-c2856ceec2e7542fe9b0bf104afeeeeb57d6996d.tar.bz2
c++: Tweaks for value_dependent_expression_p.
We may not call value_dependent_expression_p on expressions that are not potential constant expressions, otherwise value_d could crash, as I saw recently (in C++98). So beef up the checking in i_d_e_p. This revealed a curious issue: when we have __PRETTY_FUNCTION__ in a template function, we set its DECL_VALUE_EXPR to error_mark_node (cp_make_fname_decl), so potential_c_e returns false when it gets it, but value_dependent_expression_p handles it specially and says true. This broke lambda-generic-pretty1.C. So take care of that. And then also tweak uses_template_parms. gcc/cp/ChangeLog: * constexpr.c (potential_constant_expression_1): Treat __PRETTY_FUNCTION__ inside a template function as potentially-constant. * pt.c (uses_template_parms): Call instantiation_dependent_expression_p instead of value_dependent_expression_p. (instantiation_dependent_expression_p): Check potential_constant_expression before calling value_dependent_expression_p.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constexpr.c5
-rw-r--r--gcc/cp/pt.c5
2 files changed, 8 insertions, 2 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 83c3bb4..7033a49 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -7714,6 +7714,11 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
}
return false;
}
+ /* Treat __PRETTY_FUNCTION__ inside a template function as
+ potentially-constant. */
+ else if (DECL_PRETTY_FUNCTION_P (t)
+ && DECL_VALUE_EXPR (t) == error_mark_node)
+ return true;
return RECUR (DECL_VALUE_EXPR (t), rval);
}
if (want_rval
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index aa162d2..c3492f6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10755,7 +10755,7 @@ uses_template_parms (tree t)
else if (t == error_mark_node)
dependent_p = false;
else
- dependent_p = value_dependent_expression_p (t);
+ dependent_p = instantiation_dependent_expression_p (t);
processing_template_decl = saved_processing_template_decl;
@@ -27294,7 +27294,8 @@ bool
instantiation_dependent_expression_p (tree expression)
{
return (instantiation_dependent_uneval_expression_p (expression)
- || value_dependent_expression_p (expression));
+ || (potential_constant_expression (expression)
+ && value_dependent_expression_p (expression)));
}
/* Like type_dependent_expression_p, but it also works while not processing