[cfe-commits] r80211 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/member-initializers.cpp

Anders Carlsson andersca at mac.com
Wed Aug 26 22:57:30 PDT 2009


Author: andersca
Date: Thu Aug 27 00:57:30 2009
New Revision: 80211

URL: http://llvm.org/viewvc/llvm-project?rev=80211&view=rev
Log:
Don't check member and base initializers if the constructor is dependent.

Added:
    cfe/trunk/test/SemaTemplate/member-initializers.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=80211&r1=80210&r2=80211&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Aug 27 00:57:30 2009
@@ -947,40 +947,46 @@
     Diag(ColonLoc, diag::err_only_constructors_take_base_inits);
     return;
   }
-  llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members;
-  bool err = false;
-  for (unsigned i = 0; i < NumMemInits; i++) {
-    CXXBaseOrMemberInitializer *Member = 
-      static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]);
-    void *KeyToMember = GetKeyForMember(Member);
-    CXXBaseOrMemberInitializer *&PrevMember = Members[KeyToMember];
-    if (!PrevMember) {
-      PrevMember = Member;
-      continue;
+  
+  if (!Constructor->isDependentContext()) {
+    llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members;
+    bool err = false;
+    for (unsigned i = 0; i < NumMemInits; i++) {
+      CXXBaseOrMemberInitializer *Member = 
+        static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]);
+      void *KeyToMember = GetKeyForMember(Member);
+      CXXBaseOrMemberInitializer *&PrevMember = Members[KeyToMember];
+      if (!PrevMember) {
+        PrevMember = Member;
+        continue;
+      }
+      if (FieldDecl *Field = Member->getMember())
+        Diag(Member->getSourceLocation(), 
+             diag::error_multiple_mem_initialization)
+        << Field->getNameAsString();
+      else {
+        Type *BaseClass = Member->getBaseClass();
+        assert(BaseClass && "ActOnMemInitializers - neither field or base");
+        Diag(Member->getSourceLocation(),  
+             diag::error_multiple_base_initialization)
+          << BaseClass->getDesugaredType(true);
+      }
+      Diag(PrevMember->getSourceLocation(), diag::note_previous_initializer)
+        << 0;
+      err = true;
     }
-    if (FieldDecl *Field = Member->getMember())
-      Diag(Member->getSourceLocation(), 
-           diag::error_multiple_mem_initialization)
-      << Field->getNameAsString();
-    else {
-      Type *BaseClass = Member->getBaseClass();
-      assert(BaseClass && "ActOnMemInitializers - neither field or base");
-      Diag(Member->getSourceLocation(),  
-           diag::error_multiple_base_initialization)
-        << BaseClass->getDesugaredType(true);
-    }
-    Diag(PrevMember->getSourceLocation(), diag::note_previous_initializer)
-      << 0;
-    err = true;
-  }
   
-  if (err)
-    return;
+    if (err)
+      return;
+  }
   
   BuildBaseOrMemberInitializers(Context, Constructor,
                       reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), 
                       NumMemInits);
   
+  if (Constructor->isDependentContext())
+    return;
+  
   if (Diags.getDiagnosticLevel(diag::warn_base_initialized) == 
       Diagnostic::Ignored &&
       Diags.getDiagnosticLevel(diag::warn_field_initialized) == 

Added: cfe/trunk/test/SemaTemplate/member-initializers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-initializers.cpp?rev=80211&view=auto

==============================================================================
--- cfe/trunk/test/SemaTemplate/member-initializers.cpp (added)
+++ cfe/trunk/test/SemaTemplate/member-initializers.cpp Thu Aug 27 00:57:30 2009
@@ -0,0 +1,13 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T> struct A {
+  A() : j(10), i(10) { }
+  
+  int i;
+  int j;
+};
+
+template<typename T> struct B : A<T> {
+  B() : A<T>() { }
+};
+





More information about the cfe-commits mailing list