1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -verify -std=c++11 %s 29f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 39f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithnamespace N { 49f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith typedef char C; 59f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith} 69f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 79f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithnamespace M { 89f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith typedef double D; 99f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith} 109f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 119f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct NonLiteral { 129f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith NonLiteral() {} 1386c3ae46250cdcc57778c27826060779a92f3815Richard Smith NonLiteral(int) {} // expected-note 2{{here}} 149f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith operator int() const { return 0; } 159f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 169f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct Literal { 179f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith constexpr Literal() {} 189f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith operator int() const { return 0; } 199f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 209f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 219f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct S { 2286c3ae46250cdcc57778c27826060779a92f3815Richard Smith virtual int ImplicitlyVirtual() const; 239f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 249f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct T {}; 259f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 269f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithtemplate<typename T> struct ImplicitVirtualFromDependentBase : T { 27840462670ba7a6bc26265a2306b35f2f0f01f51cRichard Smith constexpr int ImplicitlyVirtual() const { return 0; } 289f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 299f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 3086c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr int a = ImplicitVirtualFromDependentBase<S>().ImplicitlyVirtual(); // expected-error {{constant expression}} expected-note {{cannot evaluate virtual function call}} 319f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithconstexpr int b = ImplicitVirtualFromDependentBase<T>().ImplicitlyVirtual(); // ok 3286c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr int c = ImplicitVirtualFromDependentBase<S>().ImplicitVirtualFromDependentBase<S>::ImplicitlyVirtual(); 339f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 349f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithtemplate<typename R> struct ConstexprMember { 35840462670ba7a6bc26265a2306b35f2f0f01f51cRichard Smith constexpr R F() const { return 0; } 369f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 3786c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr int d = ConstexprMember<int>().F(); // ok 38ef8225444452a1486bd721f3285301fe84643b00Stephen Hinesconstexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}} expected-note {{non-literal type 'const NonLiteral' cannot be used in a constant expression}} 399f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 4086c3ae46250cdcc57778c27826060779a92f3815Richard Smithtemplate<typename ...P> struct ConstexprCtor { 4186c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr ConstexprCtor(P...) {} 429f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith}; 4386c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr ConstexprCtor<> f1() { return {}; } // ok 4486c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr ConstexprCtor<int> f2() { return 0; } // ok 4586c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr ConstexprCtor<NonLiteral> f3() { return { 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} 4686c3ae46250cdcc57778c27826060779a92f3815Richard Smithconstexpr ConstexprCtor<int, NonLiteral> f4() { return { 0, 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} 479f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 489f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithstruct VirtBase : virtual S {}; // expected-note {{here}} 499f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 509f569cca2a4c5fb6026005434e27025b9e71309dRichard Smithnamespace TemplateVBase { 519f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith template<typename T> struct T1 : virtual Literal { // expected-note {{here}} 5286c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr T1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}} 539f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith }; 549f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 5586c3ae46250cdcc57778c27826060779a92f3815Richard Smith template<typename T> struct T2 : virtual T { 569f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // FIXME: This is ill-formed (no diagnostic required). 579f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith // We should diagnose it now rather than waiting until instantiation. 5886c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr T2() {} 599f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith }; 6086c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr T2<Literal> g2() { return {}; } 619f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith 629f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith template<typename T> class T3 : public T { // expected-note {{class with virtual base class is not a literal type}} 639f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith public: 649f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith constexpr T3() {} 659f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith }; 6686c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr T3<Literal> g3() { return {}; } // ok 6786c3ae46250cdcc57778c27826060779a92f3815Richard Smith constexpr T3<VirtBase> g4() { return {}; } // expected-error {{not a literal type}} 689f569cca2a4c5fb6026005434e27025b9e71309dRichard Smith} 69