Skip to content

Commit 802d8d9

Browse files
authored
[Clang] Don't ditch typo-corrected lookup result (#139374)
For a member function call like 'foo.bar<int>()', there are two typo-correction points after parsing the dot. The first occurs in ParseOptionalCXXScopeSpecifier, which tries to annotate the template name following any scope specifiers. If the template name bar is not found within 'foo', the parser was previously instructed to drop any function templates found outside of the scope. This was intended to prevent ambiguity in expressions like 'foo->bar < 7', as explained in commit 50a3cdd. However, it's unnecessary to discard typo-corrected results that were strictly resolved within the scope 'foo'. We won't perform a second typo-correction in ParseUnqualifiedId after the name being annotated. Fixes #139226
1 parent 5fa64d6 commit 802d8d9

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clang/docs/ReleaseNotes.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ Improvements to Clang's diagnostics
517517

518518
- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about overlapping and non-overlapping ranges involving character literals and floating-point literals.
519519
The warning message for non-overlapping cases has also been improved (#GH13473).
520-
520+
521+
- Fixed a duplicate diagnostic when performing typo correction on function template
522+
calls with explicit template arguments. (#GH139226)
523+
521524
Improvements to Clang's time-trace
522525
----------------------------------
523526

clang/lib/Sema/SemaTemplate.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ bool Sema::LookupTemplateName(LookupResult &Found, Scope *S, CXXScopeSpec &SS,
523523
if (Found.isAmbiguous()) {
524524
Found.clear();
525525
} else if (!Found.empty()) {
526+
// Do not erase the typo-corrected result to avoid duplicated
527+
// diagnostics.
528+
AllowFunctionTemplatesInLookup = true;
526529
Found.setLookupName(Corrected.getCorrection());
527530
if (LookupCtx) {
528531
std::string CorrectedStr(Corrected.getAsString(getLangOpts()));

clang/test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,16 @@ namespace PR11856 {
9898
}
9999
}
100100
}
101+
102+
namespace GH139226 {
103+
104+
struct Foo {
105+
template <class T> void LookupWithID(); // expected-note {{declared here}}
106+
};
107+
108+
void test(Foo &f) {
109+
f.LookupWithId<int>();
110+
// expected-error@-1 {{did you mean 'LookupWithID'}}
111+
}
112+
113+
}

0 commit comments

Comments
 (0)