[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

Serge Preis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 24 09:46:04 PDT 2017


Serge_Preis created this revision.

This patch fixes incorrect source positions of dependent c'tor initializers like in the following code:

template<typename MyBase>
struct Derived:  MyBase::InnerIterator
{

  Derived() : MyBase::InnerIterator() {}  /// This line is problematic: all positions point to InnerIterator and nothing points to MyBase

};

Bug is described at https://bugs.llvm.org/show_bug.cgi?id=26195 in comments. The issue affects TypeLoc for 'MyBase', NestedNameSpecifierLoc for 'MyBase' and CXXCtorInitializer for MyBase::InnerIterator. Reproducing matcher and source codes for bad (dependent name) and good (indepent name) behaviors are attached. Reports of bad, good and bad with patch are given in comments for comparison.

The patch basically replicates code found later in routine for ElaboratedTypeLoc and adapted to DependentTypeLoc returned from CheckTypenameType().


https://reviews.llvm.org/D32439

Files:
  SemaDeclCXX.cpp


Index: SemaDeclCXX.cpp
===================================================================
--- SemaDeclCXX.cpp
+++ SemaDeclCXX.cpp
@@ -3767,6 +3767,12 @@
           if (BaseType.isNull())
             return true;
 
+          TInfo = Context.CreateTypeSourceInfo(BaseType);
+          DependentNameTypeLoc TL = TInfo->getTypeLoc().castAs<DependentNameTypeLoc>();
+          TL.setNameLoc(IdLoc);
+          TL.setElaboratedKeywordLoc(SourceLocation());
+          TL.setQualifierLoc(SS.getWithLocInContext(Context));
+
           R.clear();
           R.setLookupName(MemberOrBase);
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32439.96408.patch
Type: text/x-patch
Size: 595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170424/9117a523/attachment.bin>


More information about the cfe-commits mailing list