Skip to content

Commit dd32c3d

Browse files
cor3ntinFznamznon
andauthored
[Clang] Only check exprs that might be immediate escalating in evaluated contexts (#93187)
As per https://eel.is/c++draft/expr.const#17 Fixes #91308 --------- Co-authored-by: Mariya Podchishchaeva <[email protected]>
1 parent 5a81db3 commit dd32c3d

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ Bug Fixes to C++ Support
769769
- Fixed a crash when trying to emit captures in a lambda call operator with an explicit object
770770
parameter that is called on a derived type of the lambda.
771771
Fixes (#GH87210), (GH89541).
772+
- Clang no longer tries to check if an expression is immediate-escalating in an unevaluated context.
773+
Fixes (#GH91308).
772774

773775
Bug Fixes to AST Handling
774776
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Sema/Sema.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,6 +5112,13 @@ class Sema final : public SemaBase {
51125112
Context == ExpressionEvaluationContext::UnevaluatedList;
51135113
}
51145114

5115+
bool isPotentiallyEvaluated() const {
5116+
return Context == ExpressionEvaluationContext::PotentiallyEvaluated ||
5117+
Context ==
5118+
ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed ||
5119+
Context == ExpressionEvaluationContext::ConstantEvaluated;
5120+
}
5121+
51155122
bool isConstantEvaluated() const {
51165123
return Context == ExpressionEvaluationContext::ConstantEvaluated ||
51175124
Context == ExpressionEvaluationContext::ImmediateFunctionContext;
@@ -5146,6 +5153,12 @@ class Sema final : public SemaBase {
51465153
return ExprEvalContexts.back();
51475154
};
51485155

5156+
const ExpressionEvaluationContextRecord &parentEvaluationContext() const {
5157+
assert(ExprEvalContexts.size() >= 2 &&
5158+
"Must be in an expression evaluation context");
5159+
return ExprEvalContexts[ExprEvalContexts.size() - 2];
5160+
};
5161+
51495162
bool isBoundsAttrContext() const {
51505163
return ExprEvalContexts.back().ExprContext ==
51515164
ExpressionEvaluationContextRecord::ExpressionKind::

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4788,8 +4788,13 @@ TemplateDeductionResult Sema::DeduceTemplateArguments(
47884788
DeduceReturnType(Specialization, Info.getLocation(), false))
47894789
return TemplateDeductionResult::MiscellaneousDeductionFailure;
47904790

4791+
// [C++26][expr.const]/p17
4792+
// An expression or conversion is immediate-escalating if it is not initially
4793+
// in an immediate function context and it is [...]
4794+
// a potentially-evaluated id-expression that denotes an immediate function.
47914795
if (IsAddressOfFunction && getLangOpts().CPlusPlus20 &&
47924796
Specialization->isImmediateEscalating() &&
4797+
parentEvaluationContext().isPotentiallyEvaluated() &&
47934798
CheckIfFunctionSpecializationIsImmediate(Specialization,
47944799
Info.getLocation()))
47954800
return TemplateDeductionResult::MiscellaneousDeductionFailure;

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,11 @@ int h(int x) {
446446
}
447447

448448
#endif
449+
450+
451+
namespace GH91308 {
452+
constexpr void f(auto) {
453+
static_assert(false);
454+
}
455+
using R1 = decltype(&f<int>);
456+
}

0 commit comments

Comments
 (0)