r255420 - Preserve source location information for qualified names used in a constructor

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 11 18:17:54 PST 2015


Author: rsmith
Date: Fri Dec 11 20:17:54 2015
New Revision: 255420

URL: http://llvm.org/viewvc/llvm-project?rev=255420&view=rev
Log:
Preserve source location information for qualified names used in a constructor
initializer list to name a base class. Patch by Shahms King!

Added:
    cfe/trunk/test/Index/namespaced-base-ctor-init.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=255420&r1=255419&r2=255420&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Dec 11 20:17:54 2015
@@ -2980,10 +2980,15 @@ Sema::BuildMemInitializer(Decl *Construc
     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));
+      }
     }
   }
 

Added: cfe/trunk/test/Index/namespaced-base-ctor-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/namespaced-base-ctor-init.cpp?rev=255420&view=auto
==============================================================================
--- cfe/trunk/test/Index/namespaced-base-ctor-init.cpp (added)
+++ cfe/trunk/test/Index/namespaced-base-ctor-init.cpp Fri Dec 11 20:17:54 2015
@@ -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]




More information about the cfe-commits mailing list