Skip to content

Commit 7337f29

Browse files
committed
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.
1 parent 905b9ca commit 7337f29

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16582,8 +16582,13 @@ static OdrUseContext isOdrUseContext(Sema &SemaRef) {
1658216582
}
1658316583

1658416584
static bool isImplicitlyDefinableConstexprFunction(FunctionDecl *Func) {
16585-
return Func->isConstexpr() &&
16586-
(Func->isImplicitlyInstantiable() || !Func->isUserProvided());
16585+
if (!Func->isConstexpr())
16586+
return false;
16587+
16588+
if (Func->isImplicitlyInstantiable() || !Func->isUserProvided())
16589+
return true;
16590+
auto *CCD = dyn_cast<CXXConstructorDecl>(Func);
16591+
return CCD && CCD->getInheritedConstructor();
1658716592
}
1658816593

1658916594
/// Mark a function referenced, and check whether it is odr-used

clang/test/SemaCXX/cxx11-inheriting-ctors.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,12 @@ namespace implicit_member_srcloc {
133133
S0<int> s0;
134134
}
135135
}
136+
137+
namespace PR47555 {
138+
struct A { constexpr A(int) {} };
139+
struct B : A { using A::A; };
140+
template<typename> void f() {
141+
constexpr B b = 0;
142+
};
143+
template void f<int>();
144+
}

0 commit comments

Comments
 (0)