diff options
author | Marek Polacek <polacek@redhat.com> | 2024-04-02 12:59:38 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-04-05 09:10:46 -0400 |
commit | 8c9063825ce726fcbbc067d8a6d062cc2d4acf5e (patch) | |
tree | 34902fe1b8499634129c3df267494fee3939d393 /gcc/expr.cc | |
parent | a844095e17c1a5aada1364c6f6eaade87ead463c (diff) | |
download | gcc-8c9063825ce726fcbbc067d8a6d062cc2d4acf5e.zip gcc-8c9063825ce726fcbbc067d8a6d062cc2d4acf5e.tar.gz gcc-8c9063825ce726fcbbc067d8a6d062cc2d4acf5e.tar.bz2 |
c++: constexpr error with fn redecl in local scope [PR111132]
We evaluate constexpr functions on the original, pre-genericization bodies.
That means that the function body we're evaluating will not have gone
through cp_genericize_r's "Map block scope extern declarations to visible
declarations with the same name and type in outer scopes if any". Here:
constexpr bool bar() { return true; } // #1
constexpr bool foo() {
constexpr bool bar(void); // #2
return bar();
}
it means that we:
1) register_constexpr_fundef (#1)
2) cp_genericize (#1)
nothing interesting happens
3) register_constexpr_fundef (foo)
does copy_fn, so we have two copies of the BIND_EXPR
4) cp_genericize (foo)
this remaps #2 to #1, but only on one copy of the BIND_EXPR
5) retrieve_constexpr_fundef (foo)
we find it, no problem
6) retrieve_constexpr_fundef (#2)
and here #2 isn't found in constexpr_fundef_table, because
we're working on the BIND_EXPR copy where #2 wasn't mapped to #1
so we fail. We've only registered #1.
It should work to use DECL_LOCAL_DECL_ALIAS (which used to be
extern_decl_map). We evaluate constexpr functions on pre-cp_fold
bodies to avoid diagnostic problems, but the remapping I'm proposing
should not interfere with diagnostics.
This is not a problem for a global scope redeclaration; there we go
through duplicate_decls which keeps the DECL_UID:
DECL_UID (olddecl) = olddecl_uid;
and DECL_UID is what constexpr_fundef_hasher::hash uses.
PR c++/111132
gcc/cp/ChangeLog:
* constexpr.cc (get_function_named_in_call): Use
cp_get_fndecl_from_callee.
* cvt.cc (cp_get_fndecl_from_callee): If there's a
DECL_LOCAL_DECL_ALIAS, use it.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/constexpr-redeclaration3.C: New test.
* g++.dg/cpp0x/constexpr-redeclaration4.C: New test.
Diffstat (limited to 'gcc/expr.cc')
0 files changed, 0 insertions, 0 deletions