aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constexpr-dynamic18.C
blob: 25d98c2b661f31fa00456ec820e4bc116fe9c00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// PR c++/93414 - poor diagnostic for dynamic_cast in constexpr context.
// { dg-do compile { target c++20 } }
// Here 'b' doesn't point/refer to a public base of Derived.

struct Base {
    constexpr virtual ~Base(){}
};

struct Derived: Base {
    constexpr ~Derived(){}
};

constexpr const Derived& cast(const Base& b) {
    return dynamic_cast<const Derived&>(b); // { dg-error "reference .dynamic_cast. failed" }
// { dg-message "dynamic type .const Base. of its operand does not have a base class of type .Derived." "" { target *-*-* } .-1 }
}

auto test() {
    static constexpr Base b;
    constexpr auto res = cast(b);
    return res;
}