]> granicus.if.org Git - clang/commitdiff
[Index] fix USR generation for namespace{extern{X}}
authorSam McCall <sam.mccall@gmail.com>
Fri, 2 Feb 2018 14:13:37 +0000 (14:13 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 2 Feb 2018 14:13:37 +0000 (14:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324093 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/USRGeneration.cpp
test/Index/USR/linkage.cpp [new file with mode: 0644]

index 3a06554b256c6c2cbd3b475e075f54b0574b25a0..ee1c950eb69d7f5f57aab97306eecc3e66d92425 100644 (file)
@@ -103,7 +103,7 @@ public:
   void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D);
 
   void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
-    IgnoreResults = true;
+    IgnoreResults = true; // No USRs for linkage specs themselves.
   }
 
   void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
@@ -192,6 +192,8 @@ bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
 void USRGenerator::VisitDeclContext(const DeclContext *DC) {
   if (const NamedDecl *D = dyn_cast<NamedDecl>(DC))
     Visit(D);
+  else if (isa<LinkageSpecDecl>(DC)) // Linkage specs are transparent in USRs.
+    VisitDeclContext(DC->getParent());
 }
 
 void USRGenerator::VisitFieldDecl(const FieldDecl *D) {
diff --git a/test/Index/USR/linkage.cpp b/test/Index/USR/linkage.cpp
new file mode 100644 (file)
index 0000000..fec80da
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+// Linkage decls are skipped in USRs for enclosed items.
+// Linkage decls themselves don't have USRs (no lines between ns and X).
+// CHECK: {{[0-9]+}}:11 | namespace/C++ | ns | c:@N@ns |
+// CHECK-NEXT: {{[0-9]+}}:33 | variable/C | X | c:@N@ns@X |
+namespace ns { extern "C" { int X; } }