Skip to content

Commit 9674d15

Browse files
committed
[FOLD] disable type correction when disambiguating
1 parent 497210d commit 9674d15

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12103,25 +12103,31 @@ class Sema final : public SemaBase {
1210312103
}
1210412104
};
1210512105

12106+
class DisableTypoCorrectionRAII {
12107+
Sema &SemaRef;
12108+
bool PrevDisableTypoCorrection;
12109+
12110+
public:
12111+
explicit DisableTypoCorrectionRAII(Sema &SemaRef)
12112+
: SemaRef(SemaRef), PrevDisableTypoCorrection(std::exchange(
12113+
SemaRef.DisableTypoCorrection, true)) {}
12114+
12115+
~DisableTypoCorrectionRAII() {
12116+
SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection;
12117+
}
12118+
};
12119+
1210612120
/// RAII class used to indicate that we are performing provisional
1210712121
/// semantic analysis to determine the validity of a construct, so
1210812122
/// typo-correction and diagnostics in the immediate context (not within
1210912123
/// implicitly-instantiated templates) should be suppressed.
12110-
class TentativeAnalysisScope {
12111-
Sema &SemaRef;
12124+
class TentativeAnalysisScope : public DisableTypoCorrectionRAII {
1211212125
// FIXME: Using a SFINAETrap for this is a hack.
1211312126
SFINAETrap Trap;
12114-
bool PrevDisableTypoCorrection;
1211512127

1211612128
public:
1211712129
explicit TentativeAnalysisScope(Sema &SemaRef)
12118-
: SemaRef(SemaRef), Trap(SemaRef, true),
12119-
PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) {
12120-
SemaRef.DisableTypoCorrection = true;
12121-
}
12122-
~TentativeAnalysisScope() {
12123-
SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection;
12124-
}
12130+
: DisableTypoCorrectionRAII(SemaRef), Trap(SemaRef, true) {}
1212512131
};
1212612132

1212712133
/// For each declaration that involved template argument deduction, the

clang/lib/Parse/ParseTemplate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,15 +1803,15 @@ bool Parser::checkPotentialAngleBracketDelimiter(
18031803
}
18041804

18051805
if (OpToken.is(tok::greater) && Tok.is(tok::coloncolon)) {
1806+
Sema::DisableTypoCorrectionRAII DTC(Actions);
1807+
18061808
SourceLocation StartLoc = Tok.getLocation();
18071809
CXXScopeSpec SS;
18081810
ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
18091811
/*ObjectHasErrors=*/false,
18101812
/*EnteringContext=*/false);
18111813
ExprResult Result =
18121814
tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false);
1813-
bool Invalid = !Result.isUsable() || Result.get()->containsErrors();
1814-
Result = Actions.CorrectDelayedTyposInExpr(Result);
18151815

18161816
if (PP.isBacktrackEnabled())
18171817
PP.RevertCachedTokens(1);
@@ -1825,7 +1825,7 @@ bool Parser::checkPotentialAngleBracketDelimiter(
18251825
Tok.setAnnotationEndLoc(EndLoc);
18261826
PP.AnnotateCachedTokens(Tok);
18271827

1828-
if (Invalid) {
1828+
if (Result.isInvalid()) {
18291829
Actions.diagnoseExprIntendedAsTemplateName(
18301830
getCurScope(), LAngle.TemplateName, LAngle.LessLoc,
18311831
OpToken.getLocation());

0 commit comments

Comments
 (0)