[cfe-commits] r91927 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp test/SemaCXX/copy-constructor-error.cpp test/SemaCXX/default2.cpp test/SemaCXX/direct-initializer.cpp utils/C++Tests/LLVM-Code-Compile/lit.local.cfg utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg

Douglas Gregor dgregor at apple.com
Tue Dec 22 14:17:25 PST 2009


Author: dgregor
Date: Tue Dec 22 16:17:25 2009
New Revision: 91927

URL: http://llvm.org/viewvc/llvm-project?rev=91927&view=rev
Log:
Switch Sema::AddCXXDirectInitializerToDecl over to InitializationSequence

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaExprCXX.cpp
    cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
    cfe/trunk/test/SemaCXX/copy-constructor-error.cpp
    cfe/trunk/test/SemaCXX/default2.cpp
    cfe/trunk/test/SemaCXX/direct-initializer.cpp
    cfe/trunk/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg
    cfe/trunk/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Dec 22 16:17:25 2009
@@ -1985,7 +1985,7 @@
   /// non-empty, will create a new CXXExprWithTemporaries expression.
   /// Otherwise, just returs the passed in expression.
   Expr *MaybeCreateCXXExprWithTemporaries(Expr *SubExpr);
-
+  OwningExprResult MaybeCreateCXXExprWithTemporaries(OwningExprResult SubExpr);
   FullExpr CreateFullExpr(Expr *SubExpr);
   
   virtual OwningExprResult ActOnFinishFullExpr(ExprArg Expr);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Dec 22 16:17:25 2009
@@ -3927,53 +3927,50 @@
   if (const ArrayType *Array = Context.getAsArrayType(DeclInitType))
     DeclInitType = Context.getBaseElementType(Array);
 
-  // FIXME: This isn't the right place to complete the type.
   if (RequireCompleteType(VDecl->getLocation(), VDecl->getType(),
                           diag::err_typecheck_decl_incomplete_type)) {
     VDecl->setInvalidDecl();
     return;
   }
 
-  if (VDecl->getType()->isRecordType()) {
-    ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
-    
-    CXXConstructorDecl *Constructor
-      = PerformInitializationByConstructor(DeclInitType,
-                                           move(Exprs),
-                                           VDecl->getLocation(),
-                                           SourceRange(VDecl->getLocation(),
-                                                       RParenLoc),
-                                           VDecl->getDeclName(),
-                      InitializationKind::CreateDirect(VDecl->getLocation(), 
-                                                       LParenLoc, 
-                                                       RParenLoc),
-                                           ConstructorArgs);
-    if (!Constructor)
-      RealDecl->setInvalidDecl();
-    else {
-      VDecl->setCXXDirectInitializer(true);
-      if (InitializeVarWithConstructor(VDecl, Constructor, 
-                                       move_arg(ConstructorArgs)))
-        RealDecl->setInvalidDecl();
-      FinalizeVarWithDestructor(VDecl, DeclInitType);
-    }
+  // The variable can not have an abstract class type.
+  if (RequireNonAbstractType(VDecl->getLocation(), VDecl->getType(),
+                             diag::err_abstract_type_in_decl,
+                             AbstractVariableType))
+    VDecl->setInvalidDecl();
+
+  const VarDecl *Def = 0;
+  if (VDecl->getDefinition(Def)) {
+    Diag(VDecl->getLocation(), diag::err_redefinition)
+    << VDecl->getDeclName();
+    Diag(Def->getLocation(), diag::note_previous_definition);
+    VDecl->setInvalidDecl();
     return;
   }
-
-  if (NumExprs > 1) {
-    Diag(CommaLocs[0], diag::err_builtin_direct_init_more_than_one_arg)
-      << SourceRange(VDecl->getLocation(), RParenLoc);
-    RealDecl->setInvalidDecl();
+  
+  // Capture the variable that is being initialized and the style of
+  // initialization.
+  InitializedEntity Entity = InitializedEntity::InitializeVariable(VDecl);
+  
+  // FIXME: Poor source location information.
+  InitializationKind Kind
+    = InitializationKind::CreateDirect(VDecl->getLocation(),
+                                       LParenLoc, RParenLoc);
+  
+  InitializationSequence InitSeq(*this, Entity, Kind, 
+                                 (Expr**)Exprs.get(), Exprs.size());
+  OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, move(Exprs));
+  if (Result.isInvalid()) {
+    VDecl->setInvalidDecl();
     return;
   }
-
-  // Let clients know that initialization was done with a direct initializer.
+  
+  Result = MaybeCreateCXXExprWithTemporaries(move(Result));
+  VDecl->setInit(Context, Result.takeAs<Expr>());
   VDecl->setCXXDirectInitializer(true);
 
-  assert(NumExprs == 1 && "Expected 1 expression");
-  // Set the init expression, handles conversions.
-  AddInitializerToDecl(Dcl, ExprArg(*this, Exprs.release()[0]),
-                       /*DirectInit=*/true);
+  if (VDecl->getType()->getAs<RecordType>())
+    FinalizeVarWithDestructor(VDecl, DeclInitType);
 }
 
 /// \brief Add the applicable constructor candidates for an initialization

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Dec 22 16:17:25 2009
@@ -2097,6 +2097,14 @@
   return E;
 }
 
+Sema::OwningExprResult 
+Sema::MaybeCreateCXXExprWithTemporaries(OwningExprResult SubExpr) {
+  if (SubExpr.isInvalid())
+    return ExprError();
+  
+  return Owned(MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>()));
+}
+
 FullExpr Sema::CreateFullExpr(Expr *SubExpr) {
   unsigned FirstTemporary = ExprEvalContexts.back().NumTemporaries;
   assert(ExprTemporaries.size() >= FirstTemporary);

Modified: cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp (original)
+++ cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp Tue Dec 22 16:17:25 2009
@@ -15,4 +15,4 @@
 
 int i = 2; 
 N::S N::j = i;
-N::S N::j(i);
+N::S N::j2(i);

Modified: cfe/trunk/test/SemaCXX/copy-constructor-error.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/copy-constructor-error.cpp?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/copy-constructor-error.cpp (original)
+++ cfe/trunk/test/SemaCXX/copy-constructor-error.cpp Tue Dec 22 16:17:25 2009
@@ -1,13 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s 
 
-struct S { // expected-note {{candidate function}} 
-   S (S);  // expected-error {{copy constructor must pass its first argument by reference}} \\
-           // expected-note {{candidate function}}
+struct S {
+   S (S);  // expected-error {{copy constructor must pass its first argument by reference}}
 };
 
 S f();
 
 void g() { 
-  S a( f() );  // expected-error {{call to constructor of 'a' is ambiguous}}
+  S a( f() );
 }
 

Modified: cfe/trunk/test/SemaCXX/default2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default2.cpp?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/default2.cpp (original)
+++ cfe/trunk/test/SemaCXX/default2.cpp Tue Dec 22 16:17:25 2009
@@ -90,12 +90,12 @@
   }
 
   void test_Z(const Z& z) {
-    Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
+    Z z2(z); // expected-error{{no matching constructor for initialization of 'class Z'}}
   }
 };
 
 void test_Z(const Z& z) {
-  Z z2(z); // expected-error{{no matching constructor for initialization of 'z2'}}
+  Z z2(z); // expected-error{{no matching constructor for initialization of 'class Z'}}
 }
 
 struct ZZ {

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

==============================================================================
--- cfe/trunk/test/SemaCXX/direct-initializer.cpp (original)
+++ cfe/trunk/test/SemaCXX/direct-initializer.cpp Tue Dec 22 16:17:25 2009
@@ -28,7 +28,7 @@
 void g() {
   X x1(5);
   X x2(1.0, 3, 4.2);
-  X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'x3'; candidates are:}}
+  X x3(1.0, 1.0); // expected-error{{no matching constructor for initialization of 'class X'}}
   Y y(1.0);
   X x4(3.14, y);
 

Modified: cfe/trunk/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/C%2B%2BTests/LLVM-Code-Compile/lit.local.cfg?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg (original)
+++ cfe/trunk/utils/C++Tests/LLVM-Code-Compile/lit.local.cfg Tue Dec 22 16:17:25 2009
@@ -11,6 +11,7 @@
 
 # testFormat: The test format to use to interpret tests.
 target_obj_root = root.llvm_obj_root
+target_obj_root = '/Users/dgregor/Projects/llvm-build-autotools'
 cxxflags = ['-D__STDC_LIMIT_MACROS',
             '-D__STDC_CONSTANT_MACROS',
             '-Wno-sign-compare',

Modified: cfe/trunk/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/C%2B%2BTests/LLVM-Code-Syntax/lit.local.cfg?rev=91927&r1=91926&r2=91927&view=diff

==============================================================================
--- cfe/trunk/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg (original)
+++ cfe/trunk/utils/C++Tests/LLVM-Code-Syntax/lit.local.cfg Tue Dec 22 16:17:25 2009
@@ -11,6 +11,7 @@
 
 # testFormat: The test format to use to interpret tests.
 target_obj_root = root.llvm_obj_root
+target_obj_root = '/Users/dgregor/Projects/llvm-build-autotools'
 cxxflags = ['-D__STDC_LIMIT_MACROS',
             '-D__STDC_CONSTANT_MACROS',
             '-I%s/include' % root.llvm_src_root,





More information about the cfe-commits mailing list