Skip to content

Commit 4af62db

Browse files
authored
[clang][Sema] Fix crash introduced in b2cd9db (#66954)
Old iterator is invalidated upon SmallVector elements additions. Stores index instead of iterator to avoid this. Fixes #66938 PR: #66954
1 parent 43812c8 commit 4af62db

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ calculateConstraintSatisfaction(Sema &S, const Expr *ConstraintExpr,
185185
ConstraintExpr = ConstraintExpr->IgnoreParenImpCasts();
186186

187187
if (LogicalBinOp BO = ConstraintExpr) {
188-
auto EffectiveDetailEnd = Satisfaction.Details.end();
188+
size_t EffectiveDetailEndIndex = Satisfaction.Details.size();
189189
ExprResult LHSRes = calculateConstraintSatisfaction(
190190
S, BO.getLHS(), Satisfaction, Evaluator);
191191

@@ -228,9 +228,12 @@ calculateConstraintSatisfaction(Sema &S, const Expr *ConstraintExpr,
228228
// The following code removes the irrelevant diagnostic information.
229229
// FIXME: We should probably delay the addition of diagnostic information
230230
// until we know the entire expression is false.
231-
if (BO.isOr() && IsRHSSatisfied)
231+
if (BO.isOr() && IsRHSSatisfied) {
232+
auto EffectiveDetailEnd = Satisfaction.Details.begin();
233+
std::advance(EffectiveDetailEnd, EffectiveDetailEndIndex);
232234
Satisfaction.Details.erase(EffectiveDetailEnd,
233235
Satisfaction.Details.end());
236+
}
234237

235238
return BO.recreateBinOp(S, LHSRes, RHSRes);
236239
}

clang/test/SemaTemplate/concepts.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,3 +1048,19 @@ namespace GH66612 {
10481048
// expected-note@-1{{because 'int' does not satisfy 'Container'}}
10491049
// expected-note@#66612GH_END{{because 'end' would be invalid: reference to overloaded function could not be resolved; did you mean to call it?}}
10501050
}
1051+
1052+
namespace GH66938 {
1053+
template <class>
1054+
concept True = true;
1055+
1056+
template <class>
1057+
concept False = false;
1058+
1059+
template <class T>
1060+
void cand(T t)
1061+
requires False<T> || False<T> || False<T> || False<T> || False<T> ||
1062+
False<T> || False<T> || False<T> || False<T> || True<T>
1063+
{}
1064+
1065+
void test() { cand(42); }
1066+
}

0 commit comments

Comments
 (0)