From 7337f296194483e0959ff980049e2835e226f396 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 16 Sep 2020 18:08:03 -0700 Subject: [PATCH] PR47555: Inheriting constructors are implicitly definable. Don't forget to define them if they're constexpr and used inside a template; we might try to evaluate a call to them before the template is instantiated. --- clang/lib/Sema/SemaExpr.cpp | 9 +++++++-- clang/test/SemaCXX/cxx11-inheriting-ctors.cpp | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 9a4b3e3..c82febd 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -16582,8 +16582,13 @@ static OdrUseContext isOdrUseContext(Sema &SemaRef) { } static bool isImplicitlyDefinableConstexprFunction(FunctionDecl *Func) { - return Func->isConstexpr() && - (Func->isImplicitlyInstantiable() || !Func->isUserProvided()); + if (!Func->isConstexpr()) + return false; + + if (Func->isImplicitlyInstantiable() || !Func->isUserProvided()) + return true; + auto *CCD = dyn_cast(Func); + return CCD && CCD->getInheritedConstructor(); } /// Mark a function referenced, and check whether it is odr-used diff --git a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp index 7d6f4f0..5be4284 100644 --- a/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp +++ b/clang/test/SemaCXX/cxx11-inheriting-ctors.cpp @@ -133,3 +133,12 @@ namespace implicit_member_srcloc { S0 s0; } } + +namespace PR47555 { + struct A { constexpr A(int) {} }; + struct B : A { using A::A; }; + template void f() { + constexpr B b = 0; + }; + template void f(); +} -- 2.7.4