| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-std=c++20 -O3 -fsanitize=undefined" } */ |
| 3 |
|
| 4 |
long v; |
| 5 |
template <class> struct A; |
| 6 |
template <typename C, typename = A<C>, typename = C> |
| 7 |
class B; |
| 8 |
template <> |
| 9 |
struct A<char> |
| 10 |
{ |
| 11 |
static int foo(char *s, const char *t, long n) { return __builtin_memcmp(s, t, n); } |
| 12 |
}; |
| 13 |
template <typename C, typename, typename> |
| 14 |
struct B { |
| 15 |
long b; |
| 16 |
B(const C *); |
| 17 |
C *bar() const; |
| 18 |
constexpr unsigned long baz(const C *, unsigned long, unsigned long) const noexcept; |
| 19 |
void baz() { C c; baz(&c, 0, v); } |
| 20 |
}; |
| 21 |
template <typename C, typename D, typename E> |
| 22 |
constexpr unsigned long |
| 23 |
B<C, D, E>::baz(const C *s, unsigned long, unsigned long n) const noexcept |
| 24 |
{ |
| 25 |
C *x = bar(); if (!x) return b; D::foo(x, s, n); return 0; |
| 26 |
} |
| 27 |
namespace { |
| 28 |
struct F { virtual ~F() {} }; |
| 29 |
struct F2 { virtual void foo(B<char>) const; }; |
| 30 |
struct F3 : F, F2 { void foo(B<char> s) const { s.baz(); } } f; |
| 31 |
} |
| 32 |
int |
| 33 |
main() |
| 34 |
{ |
| 35 |
F *p; |
| 36 |
dynamic_cast<F2 *>(p)->foo(""); |
| 37 |
} |