]> granicus.if.org Git - clang/commitdiff
Check for delegating constructors and (currently) return an error about them.
authorSean Hunt <scshunt@csclub.uwaterloo.ca>
Sat, 8 Jan 2011 19:20:43 +0000 (19:20 +0000)
committerSean Hunt <scshunt@csclub.uwaterloo.ca>
Sat, 8 Jan 2011 19:20:43 +0000 (19:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123076 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaDeclCXX.cpp

index 56ee876724f91a8214d70f7995885a6dd3287e8b..5b5bf84b7b2e8634e594af881c079a37c69ee1d0 100644 (file)
@@ -893,6 +893,12 @@ def err_enum_redeclare_fixed_mismatch : Error<
   "enumeration previously declared with %select{non|}0fixed underlying type">;
 def err_enum_redeclare_scoped_mismatch : Error<
   "enumeration previously declared as %select{un|}0scoped">;
+
+// C++0x delegating constructors
+def err_delegation_0x_only : Error<
+  "Delegating constructors are permitted only in C++0x.">;
+def err_delegation_unimplemented : Error<
+  "Delegating constructors are not fully implemented.">;
   
 // Objective-C++
 def err_objc_decls_may_only_appear_in_global_scope : Error<
index bcb7666f43958ff18f71a2b44013e9a5dd7bc140..b860e2bd5ea9610ce292dac4d28f74d3cacdca2a 100644 (file)
@@ -2566,6 +2566,13 @@ public:
                                      CXXRecordDecl *ClassDecl,
                                      SourceLocation EllipsisLoc);
 
+  MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo,
+                                           Expr **Args, unsigned NumArgs,
+                                           SourceLocation RParenLoc,
+                                           SourceLocation LParenLoc,
+                                           CXXRecordDecl *ClassDecl,
+                                           SourceLocation EllipsisLoc);
+
   bool SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
                                    CXXBaseOrMemberInitializer **Initializers,
                                    unsigned NumInitializers, bool AnyErrors);
index e2067de96452a422942ae5526dc8925180ef9bd2..b6c6d4d038394fe3be0d0af7b2eecc314c24e38e 100644 (file)
@@ -1391,6 +1391,22 @@ Sema::BuildMemberInitializer(ValueDecl *Member, Expr **Args,
   }
 }
 
+MemInitResult
+Sema::BuildDelegatingInitializer(TypeSourceInfo *TInfo,
+                                 Expr **Args, unsigned NumArgs,
+                                 SourceLocation LParenLoc,
+                                 SourceLocation RParenLoc,
+                                 CXXRecordDecl *ClassDecl,
+                                 SourceLocation EllipsisLoc) {
+  SourceLocation Loc = TInfo->getTypeLoc().getLocalSourceRange().getBegin();
+  if (!LangOpts.CPlusPlus0x)
+    return Diag(Loc, diag::err_delegation_0x_only)
+      << TInfo->getTypeLoc().getLocalSourceRange();
+
+  return Diag(Loc, diag::err_delegation_unimplemented)
+    << TInfo->getTypeLoc().getLocalSourceRange();
+}
+
 MemInitResult
 Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo,
                            Expr **Args, unsigned NumArgs, 
@@ -1438,6 +1454,12 @@ Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo,
   const CXXBaseSpecifier *DirectBaseSpec = 0;
   const CXXBaseSpecifier *VirtualBaseSpec = 0;
   if (!Dependent) { 
+    if (Context.hasSameUnqualifiedType(QualType(ClassDecl->getTypeForDecl(),0),
+                                       BaseType))
+      return BuildDelegatingInitializer(BaseTInfo, Args, NumArgs,
+                                        LParenLoc, RParenLoc, ClassDecl,
+                                        EllipsisLoc);
+
     FindBaseInitializer(*this, ClassDecl, BaseType, DirectBaseSpec, 
                         VirtualBaseSpec);