[cfe-commits] r74541 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/constructor-initializer.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Jun 30 10:35:11 PDT 2009


Author: fjahanian
Date: Tue Jun 30 12:34:52 2009
New Revision: 74541

URL: http://llvm.org/viewvc/llvm-project?rev=74541&view=rev
Log:
More diagnostics related to initialization of direct bases
in ctor-initializer list.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/constructor-initializer.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=74541&r1=74540&r2=74541&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 30 12:34:52 2009
@@ -1604,6 +1604,8 @@
 def err_base_init_direct_and_virtual : Error<
   "base class initializer %0 names both a direct base class and an "
   "inherited virtual base class">;
+def err_not_direct_base_or_virtual : Error<
+  "type %0 is not a direct or virtual base of '%1'">;
 
 def err_in_class_initializer_non_integral_type : Error<
   "in-class initializer has non-integral, non-enumeration type %0">;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Jun 30 12:34:52 2009
@@ -750,6 +750,15 @@
   if (DirectBaseSpec && VirtualBaseSpec)
     return Diag(IdLoc, diag::err_base_init_direct_and_virtual)
       << MemberOrBase << SourceRange(IdLoc, RParenLoc);
+  // C++ [base.class.init]p2:
+  // Unless the mem-initializer-id names a nonstatic data membeer of the
+  // constructor's class ot a direst or virtual base of that class, the
+  // mem-initializer is ill-formed.
+  if (!DirectBaseSpec && !VirtualBaseSpec)
+    return Diag(IdLoc, diag::err_not_direct_base_or_virtual)
+    << BaseType << ClassDecl->getNameAsCString()
+    << SourceRange(IdLoc, RParenLoc);
+    
 
   return new CXXBaseOrMemberInitializer(BaseType, (Expr **)Args, NumArgs, 
                                         IdLoc);

Modified: cfe/trunk/test/SemaCXX/constructor-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constructor-initializer.cpp?rev=74541&r1=74540&r2=74541&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/constructor-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/constructor-initializer.cpp Tue Jun 30 12:34:52 2009
@@ -54,3 +54,15 @@
 
 H::H() : A(10) { }
 
+
+class  X {};
+class Y {};
+
+struct S : Y, virtual X {
+  S (); 
+};
+
+struct Z : S { 
+  Z() : S(), X(), E()  {} // expected-error {{type 'class E' is not a direct or virtual base of 'Z'}}
+};
+





More information about the cfe-commits mailing list