Skip to content

Commit 4943c26

Browse files
committed
Switch to checking EvaluationContext
1 parent ea9dd82 commit 4943c26

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,8 +4829,8 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
48294829
/*AdjustExceptionSpec*/false);
48304830

48314831
// Unevaluated SFINAE context.
4832-
EnterExpressionEvaluationContext Unevaluated(
4833-
*this, Sema::ExpressionEvaluationContext::Unevaluated);
4832+
std::optional<EnterExpressionEvaluationContext> Unevaluated(
4833+
std::in_place, *this, Sema::ExpressionEvaluationContext::Unevaluated);
48344834
SFINAETrap Trap(*this);
48354835

48364836
Deduced.resize(TemplateParams->size());
@@ -4873,13 +4873,14 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
48734873
DeduceReturnType(Specialization, Info.getLocation(), false))
48744874
return TemplateDeductionResult::MiscellaneousDeductionFailure;
48754875

4876+
Unevaluated = std::nullopt;
48764877
// [C++26][expr.const]/p17
48774878
// An expression or conversion is immediate-escalating if it is not initially
48784879
// in an immediate function context and it is [...]
48794880
// a potentially-evaluated id-expression that denotes an immediate function.
48804881
if (IsAddressOfFunction && getLangOpts().CPlusPlus20 &&
48814882
Specialization->isImmediateEscalating() &&
4882-
parentEvaluationContext().isPotentiallyEvaluated() &&
4883+
currentEvaluationContext().isPotentiallyEvaluated() &&
48834884
CheckIfFunctionSpecializationIsImmediate(Specialization,
48844885
Info.getLocation()))
48854886
return TemplateDeductionResult::MiscellaneousDeductionFailure;

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5836,8 +5836,11 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
58365836
// With CWG2369, we substitute constraints before instantiating the associated
58375837
// function template. This helps prevent potential code generation for
58385838
// dependent types, particularly under the MS ABI.
5839-
if (!inConstraintSubstitution() ||
5840-
!getLambdaAwareParentOfDeclContext(Function)->isDependentContext()) {
5839+
bool InUnevaluatedOrImmediateContext =
5840+
llvm::any_of(ExprEvalContexts, [](auto &Context) {
5841+
return Context.isUnevaluated() || Context.isImmediateFunctionContext();
5842+
});
5843+
if (!InUnevaluatedOrImmediateContext) {
58415844
DeclGroupRef DG(Function);
58425845
Consumer.HandleTopLevelDecl(DG);
58435846
}

clang/test/CodeGenCXX/ms-mangle-requires.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concept is_derived_from_optional =
1414
requires(Tp param) { []<class Up>(Up) {}(param); };
1515

1616
template <class Tp, class Up>
17-
requires(is_derived_from_optional<Up>)
17+
requires(is_derived_from_optional<Up> && []<class W>(W) { return true; }(Up()))
1818
compare_three_way_result_t<Tp, Up> operator<=>(Tp, Up);
1919

2020
struct RuntimeModeArgs {

0 commit comments

Comments
 (0)