[cfe-commits] r93871 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/dependent-base-member-init.cpp

Douglas Gregor dgregor at apple.com
Mon Jan 18 22:46:48 PST 2010


Author: dgregor
Date: Tue Jan 19 00:46:48 2010
New Revision: 93871

URL: http://llvm.org/viewvc/llvm-project?rev=93871&view=rev
Log:
In a mem-initializer, a nested-name-specifier followed by an
identifier always names a type. In the case of a dependent
nested-name-specifier, build a TypenameType to describe the dependent
base type. I'd like to move more of this behavior up into the parser,
but this fixes PR6062.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaTemplate/dependent-base-member-init.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=93871&r1=93870&r2=93871&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Jan 19 00:46:48 2010
@@ -1062,8 +1062,23 @@
     if (!TyD) {
       if (R.isAmbiguous()) return true;
 
+      if (SS.isSet() && isDependentScopeSpecifier(SS)) {
+        bool NotUnknownSpecialization = false;
+        DeclContext *DC = computeDeclContext(SS, false);
+        if (CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(DC)) 
+          NotUnknownSpecialization = !Record->hasAnyDependentBases();
+
+        if (!NotUnknownSpecialization) {
+          // When the scope specifier can refer to a member of an unknown
+          // specialization, we take it as a type name.
+          BaseType = CheckTypenameType((NestedNameSpecifier *)SS.getScopeRep(),
+                                       *MemberOrBase, SS.getRange());
+          R.clear();
+        }
+      }
+
       // If no results were found, try to correct typos.
-      if (R.empty() && 
+      if (R.empty() && BaseType.isNull() &&
           CorrectTypo(R, S, &SS, ClassDecl) && R.isSingleResult()) {
         if (FieldDecl *Member = R.getAsSingle<FieldDecl>()) {
           if (Member->getDeclContext()->getLookupContext()->Equals(ClassDecl)) {
@@ -1106,20 +1121,22 @@
         }
       }
 
-      if (!TyD) {
+      if (!TyD && BaseType.isNull()) {
         Diag(IdLoc, diag::err_mem_init_not_member_or_class)
           << MemberOrBase << SourceRange(IdLoc, RParenLoc);
         return true;
       }
     }
 
-    BaseType = Context.getTypeDeclType(TyD);
-    if (SS.isSet()) {
-      NestedNameSpecifier *Qualifier =
-        static_cast<NestedNameSpecifier*>(SS.getScopeRep());
+    if (BaseType.isNull()) {
+      BaseType = Context.getTypeDeclType(TyD);
+      if (SS.isSet()) {
+        NestedNameSpecifier *Qualifier =
+          static_cast<NestedNameSpecifier*>(SS.getScopeRep());
 
-      // FIXME: preserve source range information
-      BaseType = Context.getQualifiedNameType(Qualifier, BaseType);
+        // FIXME: preserve source range information
+        BaseType = Context.getQualifiedNameType(Qualifier, BaseType);
+      }
     }
   }
 

Modified: cfe/trunk/test/SemaTemplate/dependent-base-member-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-base-member-init.cpp?rev=93871&r1=93870&r2=93871&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-base-member-init.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-base-member-init.cpp Tue Jan 19 00:46:48 2010
@@ -34,3 +34,21 @@
   s1() {}
 };
 
+// PR6062
+namespace PR6062 {
+  template <typename T>
+  class A : public T::type
+  {
+    A() : T::type()
+    {  
+    }
+    
+    template <typename U>
+    A(U const& init)
+      : T::type(init)
+    { }
+
+    template<typename U>
+    A(U& init) : U::other_type(init) { }
+  };
+}





More information about the cfe-commits mailing list