Skip to content

Commit 7fa13a4

Browse files
zyn0217ahatanaka
authored andcommitted
Revert "[Clang] Instantiate local constexpr functions eagerly (llvm#95660)" (llvm#98991)
Unfortunately, llvm#95660 has caused a regression in DeduceReturnType(), where some of the local recursive lambdas are getting incorrectly rejected. This reverts commit 5548ea3. Also, this adds an offending case to the test. Closes llvm#98526 (cherry picked from commit 862715e)
1 parent 626a9aa commit 7fa13a4

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,6 @@ Bug Fixes to C++ Support
912912
- Fixed several bugs in capturing variables within unevaluated contexts. (#GH63845), (#GH67260), (#GH69307),
913913
(#GH88081), (#GH89496), (#GH90669) and (#GH91633).
914914
- Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368).
915-
- Clang now instantiates local constexpr functions eagerly for constant evaluators. (#GH35052), (#GH94849)
916915
- Fixed a failed assertion when attempting to convert an integer representing the difference
917916
between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366).
918917
- Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935)

clang/lib/Sema/SemaExpr.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18181,17 +18181,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
1818118181

1818218182
if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
1818318183
Func->isConstexpr()) {
18184-
if (Func->isConstexpr())
18184+
if (isa<CXXRecordDecl>(Func->getDeclContext()) &&
18185+
cast<CXXRecordDecl>(Func->getDeclContext())->isLocalClass() &&
18186+
CodeSynthesisContexts.size())
18187+
PendingLocalImplicitInstantiations.push_back(
18188+
std::make_pair(Func, PointOfInstantiation));
18189+
else if (Func->isConstexpr())
1818518190
// Do not defer instantiations of constexpr functions, to avoid the
1818618191
// expression evaluator needing to call back into Sema if it sees a
1818718192
// call to such a function.
1818818193
InstantiateFunctionDefinition(PointOfInstantiation, Func);
18189-
else if (isa<CXXRecordDecl>(Func->getDeclContext()) &&
18190-
cast<CXXRecordDecl>(Func->getDeclContext())
18191-
->isLocalClass() &&
18192-
CodeSynthesisContexts.size())
18193-
PendingLocalImplicitInstantiations.push_back(
18194-
std::make_pair(Func, PointOfInstantiation));
1819518194
else {
1819618195
Func->setInstantiationIsPending(true);
1819718196
PendingInstantiations.push_back(

clang/test/SemaTemplate/instantiate-local-class.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -512,24 +512,26 @@ namespace LambdaInDefaultMemberInitializer {
512512
}
513513

514514
#if __cplusplus >= 201703L
515-
namespace GH35052 {
516515

517-
template <typename F> constexpr int func(F f) {
518-
if constexpr (f(1UL)) {
519-
return 1;
516+
// Reduced from https://github.com/llvm/llvm-project/issues/98526
517+
// This relies on the deferral instantiation of the local lambda, otherwise we would fail in DeduceReturnType().
518+
namespace local_recursive_lambda {
519+
520+
template <typename F> struct recursive_lambda {
521+
template <typename... Args> auto operator()(Args &&...args) const {
522+
return fn(*this, args...);
520523
}
521-
return 0;
522-
}
524+
F fn;
525+
};
523526

524-
int main() {
525-
auto predicate = [](auto v) /*implicit constexpr*/ -> bool {
526-
return v == 1;
527-
};
527+
template <typename F> recursive_lambda(F) -> recursive_lambda<F>;
528528

529-
static_assert(predicate(1));
530-
return func(predicate);
529+
void foo() {
530+
recursive_lambda{[&](auto &self_fn, int) -> int {
531+
return self_fn(0);
532+
}}(0);
531533
}
532534

533-
} // namespace GH35052
535+
} // namespace local_recursive_lambda
534536

535537
#endif

0 commit comments

Comments
 (0)