[clang] [clang] use typo-corrected name qualifier for expressions (PR #183937)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 28 13:26:40 PST 2026


================
@@ -2738,6 +2738,13 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R,
                          << DroppedSpecifier << NameRange,
                      PDiag(NoteID), AcceptableWithRecovery);
 
+      if (Corrected.WillReplaceSpecifier()) {
+        NestedNameSpecifier NNS = Corrected.getCorrectionSpecifier();
+        // In order to be valid, a non-empty CXXScopeSpec needs a source range.
+        SS.MakeTrivial(Context, NNS,
+                       NNS ? NameRange.getBegin() : SourceRange());
+      }
----------------
ojhunt wrote:

This kind of pattern seems to happen a lot - I looked at the original report stack trace and I think it would be a good idea to add an assertion to  `NestedNameSpecifierLocBuilder::MakeTrivial`, e.g.

```cpp
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier,
                  SourceRange R) {
  assert(!NNS || R.isValid());
  Representation = Qualifier;
  BufferSize = 0;
  PushTrivial(Context, Qualifier, R);
}
```

Just so it gets caught earlier in the "things are going wrong" pipeline.

Also: another case where the default nullability of all these types makes me sad :-/

https://github.com/llvm/llvm-project/pull/183937


More information about the cfe-commits mailing list