]> granicus.if.org Git - clang/commitdiff
Preserve source location information for qualified names used in a constructor
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 12 Dec 2015 02:17:54 +0000 (02:17 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 12 Dec 2015 02:17:54 +0000 (02:17 +0000)
initializer list to name a base class. Patch by Shahms King!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255420 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/Index/namespaced-base-ctor-init.cpp [new file with mode: 0644]

index 3054088bd6d8729e68c46b1aaba32f4c5e42b74d..b0b362f4cdb595c8469c84376968e2a3a0df1f78 100644 (file)
@@ -2980,10 +2980,15 @@ Sema::BuildMemInitializer(Decl *ConstructorD,
     if (BaseType.isNull()) {
       BaseType = Context.getTypeDeclType(TyD);
       MarkAnyDeclReferenced(TyD->getLocation(), TyD, /*OdrUse=*/false);
-      if (SS.isSet())
-        // FIXME: preserve source range information
+      if (SS.isSet()) {
         BaseType = Context.getElaboratedType(ETK_None, SS.getScopeRep(),
                                              BaseType);
+        TInfo = Context.CreateTypeSourceInfo(BaseType);
+        ElaboratedTypeLoc TL = TInfo->getTypeLoc().castAs<ElaboratedTypeLoc>();
+        TL.getNamedTypeLoc().castAs<TypeSpecTypeLoc>().setNameLoc(IdLoc);
+        TL.setElaboratedKeywordLoc(SourceLocation());
+        TL.setQualifierLoc(SS.getWithLocInContext(Context));
+      }
     }
   }
 
diff --git a/test/Index/namespaced-base-ctor-init.cpp b/test/Index/namespaced-base-ctor-init.cpp
new file mode 100644 (file)
index 0000000..2d60f7c
--- /dev/null
@@ -0,0 +1,10 @@
+namespace ns1 {
+struct Base {};
+struct Derived : Base {
+  Derived() : ns1::Base() {}
+};
+}
+
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+// CHECK: namespaced-base-ctor-init.cpp:4:15: NamespaceRef=ns1:1:11 Extent=[4:15 - 4:18]
+// CHECK: namespaced-base-ctor-init.cpp:4:20: TypeRef=struct ns1::Base:2:8 Extent=[4:20 - 4:24]