[PATCH] D85842: Fix `NestedNameSpecifierLoc::getLocalSourceRange()`

Eduardo Caldas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 12 09:25:21 PDT 2020


eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

>From the documentation comment above `NestedNameSpecifierLoc::getLocalSourceRange()`

  /// Retrieve the source range covering just the last part of
  /// this nested-name-specifier, not including the prefix.
  ///
  /// For example, if this instance refers to a nested-name-specifier
  /// \c \::std::vector<int>::, the returned source range would cover
  /// from "vector" to the last '::'.

We would expect that for a nested-name-specifier with a dependent
template specialization type: `T::template ST<int>::`
`NestedNameSpecifierLoc::getLocalSourceRange()` would return `template
ST<int>::` but instead it returns `T::template ST<int>::`.

The issue might as well be on
`DependentTemplateSpecializationTypeLoc::getLocalSourceRange()` which is
indirectly called from `NestedNameSpecifierLoc::getLocalSourceRange()`.
I think not.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85842

Files:
  clang/lib/AST/NestedNameSpecifier.cpp


Index: clang/lib/AST/NestedNameSpecifier.cpp
===================================================================
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -439,6 +439,14 @@
     // Note: the 'template' keyword is part of the TypeLoc.
     void *TypeData = LoadPointer(Data, Offset);
     TypeLoc TL(Qualifier->getAsType(), TypeData);
+    // For `T::template ST<int>::x`
+    // `NestedNameSpecifierLoc::getLocalSourceRange()` should return `template
+    // ST<int>::` but `DependentTemplateSpecializationTypeLoc::getBeginLoc()`
+    // returns `^T::temp...`
+    if (auto DependentTL = TL.getAs<DependentTemplateSpecializationTypeLoc>()) {
+      return SourceRange(DependentTL.getTemplateKeywordLoc(),
+                         LoadSourceLocation(Data, Offset + sizeof(void *)));
+    }
     return SourceRange(TL.getBeginLoc(),
                        LoadSourceLocation(Data, Offset + sizeof(void*)));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85842.285111.patch
Type: text/x-patch
Size: 957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200812/22d83a44/attachment.bin>


More information about the cfe-commits mailing list