c++: Fix -std=c++20 ICE on virtual method call [PR99132]
authorJakub Jelinek <jakub@redhat.com>
Thu, 18 Feb 2021 15:21:52 +0000 (16:21 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 18 Feb 2021 15:21:52 +0000 (16:21 +0100)
commit3bfa96895b3219afd93a7038850baef4b63c1f82
treedb0554af17b92c82762da9c050e3df83db7c429c
parent7ee164dcfe390fc030028db9112d44255637b1aa
c++: Fix -std=c++20 ICE on virtual method call [PR99132]

On the following testcase we ICE in C++20 mode during cp_get_callee_fndecl
-> constexpr evaluation.
It is only in C++20 mode on this testcase because virtual methods can't
be constexpr in C++17 and earlier and so potential_constant_expression_1
rejects it earlier.
And the ICE is caused by genericization changing the h PARM_DECL from having
B<C *> type to B<C *> & DECL_BY_REFERENCE and the constexpr evaluation
not being able to deal with that.
I think this just shows that we shouldn't do the constexpr evaluation during
genericization and later, and other spots e.g. during gimplification
also don't call cp_get_callee_fndecl but cp_get_callee_fndecl_nofold.
After all, cp_fold has already been run and it did the folding if there
was any opportunity to do so.  And furthermore, what that cp_genericize_r
spot does is check for any left-over immediate function calls (which can be
ATM just std::source_location::current() call) and immediate functions
outside of immediate functions can't have addresses leaked into the IL,
so it will be always a direct call anyway.  And immediate functions
themselves don't make it into genericization/gimplification.

2021-02-18  Jakub Jelinek  <jakub@redhat.com>

PR c++/99132
* cp-gimplify.c (cp_genericize_r) <case CALL_EXPR>: Use
cp_get_callee_fndecl_nofold instead of cp_get_callee_fndecl to check
for immediate function calls.

* g++.dg/cpp2a/constexpr-virtual18.C: New test.
gcc/cp/cp-gimplify.c
gcc/testsuite/g++.dg/cpp2a/constexpr-virtual18.C [new file with mode: 0644]