[mlir][acc] Introduce MappableType interface (#122146)
[llvm-project.git] / clang / test / CXX / dcl.dcl / dcl.spec / dcl.constexpr / p6.cpp
blob00ef78426289fa547715497304bd8449dfe27d56
1 // RUN: %clang_cc1 -verify -std=c++11 %s
3 namespace N {
4 typedef char C;
7 namespace M {
8 typedef double D;
11 struct NonLiteral {
12 NonLiteral() {}
13 NonLiteral(int) {}
14 operator int() const { return 0; }
16 struct Literal {
17 constexpr Literal() {}
18 operator int() const { return 0; }
21 struct S {
22 virtual int ImplicitlyVirtual() const;
24 struct T {};
26 template<typename T> struct ImplicitVirtualFromDependentBase : T {
27 constexpr int ImplicitlyVirtual() const { return 0; }
30 constexpr int a = ImplicitVirtualFromDependentBase<S>().ImplicitlyVirtual(); // expected-error {{constant expression}} expected-note {{cannot evaluate call to virtual function}}
31 constexpr int b = ImplicitVirtualFromDependentBase<T>().ImplicitlyVirtual(); // ok
32 constexpr int c = ImplicitVirtualFromDependentBase<S>().ImplicitVirtualFromDependentBase<S>::ImplicitlyVirtual(); // expected-error {{constant expression}} expected-note {{cannot evaluate call to virtual function}}
34 template<typename R> struct ConstexprMember {
35 constexpr R F() const { return 0; }
37 constexpr int d = ConstexprMember<int>().F(); // ok
38 constexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}} expected-note {{non-literal type 'NonLiteral' cannot be used in a constant expression}}
40 template<typename ...P> struct ConstexprCtor {
41 constexpr ConstexprCtor(P...) {}
43 constexpr ConstexprCtor<> f1() { return {}; } // ok
44 constexpr ConstexprCtor<int> f2() { return 0; } // ok
45 constexpr ConstexprCtor<NonLiteral> f3() { return { 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-literal type 'NonLiteral}}
46 constexpr ConstexprCtor<int, NonLiteral> f4() { return { 0, 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-literal type 'NonLiteral}}
48 struct VirtBase : virtual S {}; // expected-note {{here}}
50 namespace TemplateVBase {
51 template<typename T> struct T1 : virtual Literal { // expected-note {{here}}
52 constexpr T1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}}
55 template<typename T> struct T2 : virtual T {
56 // FIXME: This is ill-formed (no diagnostic required).
57 // We should diagnose it now rather than waiting until instantiation.
58 constexpr T2() {}
60 constexpr T2<Literal> g2() { return {}; }
62 template<typename T> class T3 : public T { // expected-note {{class with virtual base class is not a literal type}}
63 public:
64 constexpr T3() {}
66 constexpr T3<Literal> g3() { return {}; } // ok
67 constexpr T3<VirtBase> g4() { return {}; } // expected-error {{not a literal type}}