aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/constexpr.cc
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2023-11-16 09:32:07 -0500
committerPatrick Palka <ppalka@redhat.com>2023-11-16 09:32:07 -0500
commit0077c0fb19981c108a01cd15af9b2d6d478c183b (patch)
treed6ed5753cd394efc25fe7fbdee712634f1066939 /gcc/cp/constexpr.cc
parent4547c271c455dcf54ce9c4bb820acdd3b6193f6d (diff)
downloadgcc-0077c0fb19981c108a01cd15af9b2d6d478c183b.zip
gcc-0077c0fb19981c108a01cd15af9b2d6d478c183b.tar.gz
gcc-0077c0fb19981c108a01cd15af9b2d6d478c183b.tar.bz2
c++: constantness of call to function pointer [PR111703]
potential_constant_expression for CALL_EXPR tests FUNCTION_POINTER_TYPE_P on the callee rather than on the type of the callee, which means we always pass want_rval=any when recursing and so may fail to identify a non-constant function pointer callee as such. Fixing this turns out to further work around PR111703. PR c++/111703 PR c++/107939 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>: Fix FUNCTION_POINTER_TYPE_P test. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-fn8.C: Extend test. * g++.dg/diagnostic/constexpr4.C: New test.
Diffstat (limited to 'gcc/cp/constexpr.cc')
-rw-r--r--gcc/cp/constexpr.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 8a6b210..344107d 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9547,7 +9547,12 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
}
else if (fun)
{
- if (RECUR (fun, FUNCTION_POINTER_TYPE_P (fun) ? rval : any))
+ if (TREE_TYPE (fun)
+ && FUNCTION_POINTER_TYPE_P (TREE_TYPE (fun)))
+ want_rval = rval;
+ else
+ want_rval = any;
+ if (RECUR (fun, want_rval))
/* Might end up being a constant function pointer. But it
could also be a function object with constexpr op(), so
we pass 'any' so that the underlying VAR_DECL is deemed