[clang] ebbeb16 - [clang] Fix the location of UsingTypeLoc.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 23 03:53:51 PST 2023
Author: Haojian Wu
Date: 2023-01-23T12:51:21+01:00
New Revision: ebbeb164c25a40cb6ba9c6b18dce5dcd06c0bb07
URL: https://github.com/llvm/llvm-project/commit/ebbeb164c25a40cb6ba9c6b18dce5dcd06c0bb07
DIFF: https://github.com/llvm/llvm-project/commit/ebbeb164c25a40cb6ba9c6b18dce5dcd06c0bb07.diff
LOG: [clang] Fix the location of UsingTypeLoc.
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;
```
Differential Revision: https://reviews.llvm.org/D142125
Added:
Modified:
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index d7ea34c3c7054..4e5c3774c1655 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -520,6 +520,13 @@ TEST(SelectionTest, CommonAncestor) {
)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) {
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e124db71af18b..16986f6f0d0e5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -6256,6 +6256,9 @@ namespace {
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.
More information about the cfe-commits
mailing list