From f368fb40dff9802a3a3548151840d4fa750b1d41 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 10 Oct 2011 16:38:04 +0000 Subject: [PATCH] constexpr: Disable checking of constructor member initializer lists for constexpr constructor templates. Such checking is optional, and currently hard to get right since clang doesn't generate implicit member initializers until instantiation (even for non-dependent members). This is needed for clang to accept libstdc++ from g++4.6 in c++0x mode. llvm-svn: 141547 --- clang/lib/Sema/SemaDeclCXX.cpp | 3 +- .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 247d8dc5bba8..4f9c0493c674 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -902,7 +902,8 @@ bool Sema::CheckConstexprFunctionBody(const FunctionDecl *Dcl, Stmt *Body) { Diag(Dcl->getLocation(), diag::err_constexpr_union_ctor_no_init); return false; } - } else if (!Constructor->isDelegatingConstructor()) { + } else if (!Constructor->isDependentContext() && + !Constructor->isDelegatingConstructor()) { assert(RD->getNumVBases() == 0 && "constexpr ctor with virtual bases"); // Skip detailed checking if we have enough initializers, and we would diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp index 4594f6cdb063..804ea9abddcf 100644 --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp @@ -150,6 +150,44 @@ struct AnonMembers { constexpr AnonMembers(int(&)[6]) {} // expected-error {{constexpr constructor must initialize all members}} }; +template using Int = int; +template +struct TemplateInit { + T a; + int b; // desired-note {{not initialized}} + Int c; // desired-note {{not initialized}} + struct { + T d; + int e; // desired-note {{not initialized}} + Int f; // desired-note {{not initialized}} + }; + struct { + Literal l; + Literal m; + Literal n[3]; + }; + union { // desired-note {{not initialized}} + T g; + T h; + }; + // FIXME: This is ill-formed (no diagnostic required). We should diagnose it. + constexpr TemplateInit() {} // desired-error {{must initialize all members}} +}; +template struct TemplateInit2 { + Literal l; + constexpr TemplateInit2() {} // ok +}; + +template struct weak_ptr { + constexpr weak_ptr() : p(0) {} + T *p; +}; +template struct enable_shared_from_this { + weak_ptr weak_this; + constexpr enable_shared_from_this() {} // ok +}; +constexpr int f(enable_shared_from_this); + // - every constructor involved in initializing non-static data members and base // class sub-objects shall be a constexpr constructor. //