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);
         }


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);
         }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to