aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2025-01-21 14:48:46 -0500
committerMarek Polacek <polacek@redhat.com>2025-01-22 10:26:46 -0500
commitcb828691fe692f9df002a2e3757a1aec68857e85 (patch)
tree8b2609f117460eb1680e1a9c32d3905184766e0f /gcc
parent27470f9a818538fadb0e458a272358c7141fcd8c (diff)
downloadgcc-cb828691fe692f9df002a2e3757a1aec68857e85.zip
gcc-cb828691fe692f9df002a2e3757a1aec68857e85.tar.gz
gcc-cb828691fe692f9df002a2e3757a1aec68857e85.tar.bz2
c++: further tweak to cxx_eval_outermost_constant_expr [PR118396]
This patch adds an error in a !allow_non_constant case when the initializer/object types don't match. PR c++/118396 gcc/cp/ChangeLog: * constexpr.cc (cxx_eval_outermost_constant_expr): Add an error call when !allow_non_constant. Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/constexpr.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 9f950ff..41ff78b 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9092,11 +9092,19 @@ cxx_eval_outermost_constant_expr (tree t, bool allow_non_constant,
return r;
else if (non_constant_p && TREE_CONSTANT (r))
r = mark_non_constant (r);
- else if (non_constant_p
- /* Check we are not trying to return the wrong type. */
- || !same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (r)))
+ else if (non_constant_p)
return t;
+ /* Check we are not trying to return the wrong type. */
+ if (!same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (r)))
+ {
+ /* If so, this is not a constant expression. */
+ if (!allow_non_constant)
+ error ("%qE is not a constant expression because it initializes "
+ "a %qT rather than %qT", t, TREE_TYPE (t), type);
+ return t;
+ }
+
if (should_unshare)
r = unshare_expr (r);