Skip to content

Commit b51ca7d

Browse files
author
Patrick Palka
committed
c++: constexpr evaluation of abi::__dynamic_cast [PR120620]
r13-3299 changed our internal declaration of __dynamic_cast to reside inside the abi/__cxxabiv1:: namespace instead of the global namespace, matching the real declaration. This inadvertently made us now attempt constexpr evaluation of user-written calls to abi::__dynamic_cast since cxx_dynamic_cast_fn_p now also returns true for them, but we're not prepared to handle arbitrary calls to __dynamic_cast, and therefore ICE. This patch restores cxx_dynamic_cast_fn_p to return true only for synthesized calls to __dynamic_cast, which can be distinguished by DECL_ARTIFICIAL, since apparently the synthesized declaration of __dynamic_cast doesn't get merged with the actual declaration. PR c++/120620 gcc/cp/ChangeLog: * constexpr.cc (cxx_dynamic_cast_fn_p): Return true only for synthesized __dynamic_cast. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/constexpr-dynamic19.C: New test. * g++.dg/cpp2a/constexpr-dynamic1a.C: New test. Reviewed-by: Jason Merrill <[email protected]>
1 parent ac421ac commit b51ca7d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

gcc/cp/constexpr.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,11 @@ cxx_dynamic_cast_fn_p (tree fndecl)
32403240
{
32413241
return (cxx_dialect >= cxx20
32423242
&& id_equal (DECL_NAME (fndecl), "__dynamic_cast")
3243-
&& CP_DECL_CONTEXT (fndecl) == abi_node);
3243+
&& CP_DECL_CONTEXT (fndecl) == abi_node
3244+
/* Only consider implementation-detail __dynamic_cast calls that
3245+
correspond to a dynamic_cast, and ignore direct calls to
3246+
abi::__dynamic_cast. */
3247+
&& DECL_ARTIFICIAL (fndecl));
32443248
}
32453249

32463250
/* Often, we have an expression in the form of address + offset, e.g.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// PR c++/120620
2+
// { dg-do compile }
3+
4+
#include <cxxabi.h>
5+
6+
struct A* a;
7+
8+
void f() {
9+
void* const p = abi::__dynamic_cast(&a, 0, 0, 42);
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Test that including <cxxabi.h>, whence the actual abi:__dynamic_cast
2+
// is declared, doesn't affect our constexpr dynamic_cast handling.
3+
// { dg-do compile { target c++20 } }
4+
5+
#include <cxxabi.h>
6+
#include "constexpr-dynamic1.C"

0 commit comments

Comments
 (0)