]> granicus.if.org Git - clang/commitdiff
Create CXXConstructExprs when constructing via copy initialization.
authorAnders Carlsson <andersca@mac.com>
Wed, 27 May 2009 16:10:08 +0000 (16:10 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 27 May 2009 16:10:08 +0000 (16:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72474 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaInit.cpp

index 3014a8e2ea6882714c699becf6ab1a05e82502a9..5b3ea40b0647fb37688b8c13c7f078392eef8241 100644 (file)
@@ -2630,9 +2630,12 @@ public:
                                    IdentifierInfo &Comp, SourceLocation CmpLoc);
   
   /// type checking declaration initializers (C99 6.7.8)
+  
+  /// FIXME: The VarDecl parameter should not have a default value,
+  /// and all call sites should be audited.
   bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
                              SourceLocation InitLoc,DeclarationName InitEntity,
-                             bool DirectInit);
+                             bool DirectInit, VarDecl *VD = 0);
   bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
   bool CheckForConstantInitializer(Expr *e, QualType t);
   
index 4149fa4c9a35ac3d90c5588371afdec65aa3f34b..5e09851770b2298bc088369aa3bb2bba4e65a810 100644 (file)
@@ -2562,7 +2562,7 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) {
       VDecl->setInvalidDecl();
     } else if (!VDecl->isInvalidDecl()) {
       if (CheckInitializerTypes(Init, DclT, VDecl->getLocation(),
-                                VDecl->getDeclName(), DirectInit))
+                                VDecl->getDeclName(), DirectInit, VDecl))
         VDecl->setInvalidDecl();
       
       // C++ 3.6.2p2, allow dynamic initialization of static initializers.
index d880c236d2dc35057c2b64afbac55a158cecc854..3fae86d19d23c8ecb541cf6b32e6536e43cb2be0 100644 (file)
@@ -18,6 +18,7 @@
 #include "Sema.h"
 #include "clang/Parse/Designator.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include <map>
 using namespace clang;
@@ -116,7 +117,7 @@ static void CheckStringInit(Expr *Str, QualType &DeclT, Sema &S) {
 bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
                                  SourceLocation InitLoc,
                                  DeclarationName InitEntity,
-                                 bool DirectInit) {
+                                 bool DirectInit, VarDecl *VD) {
   if (DeclType->isDependentType() || 
       Init->isTypeDependent() || Init->isValueDependent())
     return false;
@@ -160,7 +161,14 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
                                              InitLoc, Init->getSourceRange(),
                                              InitEntity, 
                                              DirectInit? IK_Direct : IK_Copy);
-        return Constructor == 0;
+        if (!Constructor)
+          return true;
+        
+        // FIXME: What do do if VD is null here?
+        assert(VD && "Must have a var decl to construct into!");
+        Init = CXXConstructExpr::Create(Context, VD, DeclType, Constructor, 
+                                        false, &Init, 1);
+        return false;
       }
       
       //   -- Otherwise (i.e., for the remaining copy-initialization