diff options
Diffstat (limited to 'clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp')
-rw-r--r-- | clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp index e383bc09226..1a6dc9ecfb5 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p6.cpp @@ -10,7 +10,7 @@ namespace M { struct NonLiteral { NonLiteral() {} - NonLiteral(int) {} + NonLiteral(int) {} // expected-note 2{{here}} operator int() const { return 0; } }; struct Literal { @@ -19,7 +19,7 @@ struct Literal { }; struct S { - virtual int ImplicitlyVirtual(); + virtual int ImplicitlyVirtual() const; }; struct T {}; @@ -27,48 +27,42 @@ template<typename T> struct ImplicitVirtualFromDependentBase : T { constexpr int ImplicitlyVirtual() { return 0; } }; -// FIXME: Can't test this until we have function invocation substitution -#if 0 -constexpr int a = ImplicitVirtualFromDependentBase<S>().ImplicitlyVirtual(); // desired-error {{not a constant expression}} +constexpr int a = ImplicitVirtualFromDependentBase<S>().ImplicitlyVirtual(); // expected-error {{constant expression}} expected-note {{cannot evaluate virtual function call}} constexpr int b = ImplicitVirtualFromDependentBase<T>().ImplicitlyVirtual(); // ok -#endif +constexpr int c = ImplicitVirtualFromDependentBase<S>().ImplicitVirtualFromDependentBase<S>::ImplicitlyVirtual(); template<typename R> struct ConstexprMember { constexpr R F() { return 0; } }; -// FIXME: Can't test this until we have function invocation substitution -#if 0 -constexpr int c = ConstexprMember<int>().F(); // ok -constexpr int d = ConstexprMember<NonLiteral>().F(); // desired-error {{not a constant expression}} -#endif +constexpr int d = ConstexprMember<int>().F(); // ok +constexpr int e = ConstexprMember<NonLiteral>().F(); // expected-error {{constant expression}} -template<typename ...P> struct ConstexprCtor { // expected-note 2{{no constexpr constructors}} - constexpr ConstexprCtor(P...); // expected-note {{constructor template instantiation is not constexpr because 1st parameter type 'NonLiteral' is not a literal type}} \ - expected-note {{constructor template instantiation is not constexpr because 2nd parameter type 'NonLiteral' is not a literal type}} +template<typename ...P> struct ConstexprCtor { + constexpr ConstexprCtor(P...) {} }; -constexpr ConstexprCtor<> f1(); // ok -constexpr ConstexprCtor<int> f2(); // ok -constexpr ConstexprCtor<NonLiteral> f3(); // expected-error {{not a literal type}} -constexpr ConstexprCtor<int, NonLiteral> f4(); // expected-error {{not a literal type}} +constexpr ConstexprCtor<> f1() { return {}; } // ok +constexpr ConstexprCtor<int> f2() { return 0; } // ok +constexpr ConstexprCtor<NonLiteral> f3() { return { 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} +constexpr ConstexprCtor<int, NonLiteral> f4() { return { 0, 0 }; } // expected-error {{never produces a constant expression}} expected-note {{non-constexpr constructor 'NonLiteral}} struct VirtBase : virtual S {}; // expected-note {{here}} namespace TemplateVBase { template<typename T> struct T1 : virtual Literal { // expected-note {{here}} - constexpr T1(); // expected-error {{constexpr constructor not allowed in struct with virtual base class}} + constexpr T1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}} }; - template<typename T> struct T2 : virtual T { // expected-note {{struct with virtual base class is not a literal type}} expected-note {{here}} + template<typename T> struct T2 : virtual T { // FIXME: This is ill-formed (no diagnostic required). // We should diagnose it now rather than waiting until instantiation. - constexpr T2(); // desired-error {{constexpr constructor not allowed in class with virtual base classes}} + constexpr T2() {} }; - constexpr T2<Literal> g2(); // expected-error {{not a literal type}} + constexpr T2<Literal> g2() { return {}; } template<typename T> class T3 : public T { // expected-note {{class with virtual base class is not a literal type}} public: constexpr T3() {} }; - constexpr T3<Literal> g3(); // ok - constexpr T3<VirtBase> g4(); // expected-error {{not a literal type}} + constexpr T3<Literal> g3() { return {}; } // ok + constexpr T3<VirtBase> g4() { return {}; } // expected-error {{not a literal type}} } |