[PATCH] D142125: [clang] Fix the location of UsingTypeLoc.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 19 08:14:28 PST 2023


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added projects: clang, clang-tools-extra.

It is revealed by the https://reviews.llvm.org/D141280.

  namespace ns { class Foo {}; }
  using ns::Foo;
  
  // Before the fix, the Location of UsingTypeLoc Foo points to the
  token "class", slection on ^Foo will result in the VarDecl abc.
  class Foo abc;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142125

Files:
  clang-tools-extra/clangd/unittests/SelectionTests.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -6256,6 +6256,9 @@
     void VisitTagTypeLoc(TagTypeLoc TL) {
       TL.setNameLoc(DS.getTypeSpecTypeNameLoc());
     }
+    void VisitUsingTypeLoc(UsingTypeLoc TL) {
+      TL.setNameLoc(DS.getTypeSpecTypeNameLoc());
+    }
     void VisitAtomicTypeLoc(AtomicTypeLoc TL) {
       // An AtomicTypeLoc can come from either an _Atomic(...) type specifier
       // or an _Atomic qualifier.
Index: clang-tools-extra/clangd/unittests/SelectionTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -520,6 +520,13 @@
       )cpp",
        "TypedefTypeLoc"},
 
+      {R"cpp(
+        namespace ns { class Foo {}; }
+        using ns::Foo;
+        class [[^Foo]] foo;
+      )cpp",
+       "UsingTypeLoc"},
+
       // lambda captured var-decl
       {R"cpp(
         void test(int bar) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142125.490527.patch
Type: text/x-patch
Size: 1096 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230119/d28e140a/attachment.bin>


More information about the cfe-commits mailing list