[cfe-commits] r91881 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaInit.cpp test/CXX/temp/temp.spec/temp.explicit/p1.cpp test/CXX/temp/temp.spec/temp.explicit/p10.cpp test/SemaCXX/addr-of-overloaded-function.cpp test/SemaCXX/aggregate-initialization.cpp test/SemaCXX/dcl_init_aggr.cpp test/SemaTemplate/typename-specifier-2.cpp

Eli Friedman eli.friedman at gmail.com
Mon Dec 21 18:10:53 PST 2009


Author: efriedma
Date: Mon Dec 21 20:10:53 2009
New Revision: 91881

URL: http://llvm.org/viewvc/llvm-project?rev=91881&view=rev
Log:
Switch file-scope assignment initialization over to InitializationSequence.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1.cpp
    cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p10.cpp
    cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
    cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
    cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
    cfe/trunk/test/SemaTemplate/typename-specifier-2.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 21 20:10:53 2009
@@ -3557,22 +3557,16 @@
       VDecl->setInvalidDecl();
     } else if (!VDecl->isInvalidDecl()) {
       InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1);
-      if (InitSeq) {
-        OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind,
+      OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind,
                                           MultiExprArg(*this, (void**)&Init, 1),
-                                                  &DclT);
-        if (Result.isInvalid()) {
-          VDecl->setInvalidDecl();
-          return;
-        }
-
-        Init = Result.takeAs<Expr>();
-      } else {
-        InitSeq.Diagnose(*this, Entity, Kind, &Init, 1);
+                                                &DclT);
+      if (Result.isInvalid()) {
         VDecl->setInvalidDecl();
         return;
       }
 
+      Init = Result.takeAs<Expr>();
+
       // C++ 3.6.2p2, allow dynamic initialization of static initializers.
       // Don't check invalid declarations to avoid emitting useless diagnostics.
       if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) {
@@ -3630,9 +3624,18 @@
   } else if (VDecl->isFileVarDecl()) {
     if (VDecl->getStorageClass() == VarDecl::Extern)
       Diag(VDecl->getLocation(), diag::warn_extern_init);
-    if (!VDecl->isInvalidDecl())
-      if (CheckInitializerTypes(Init, DclT, Entity, Kind))
+    if (!VDecl->isInvalidDecl()) {
+      InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1);
+      OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind,
+                                          MultiExprArg(*this, (void**)&Init, 1),
+                                                &DclT);
+      if (Result.isInvalid()) {
         VDecl->setInvalidDecl();
+        return;
+      }
+
+      Init = Result.takeAs<Expr>();
+    }
 
     // C++ 3.6.2p2, allow dynamic initialization of static initializers.
     // Don't check invalid declarations to avoid emitting useless diagnostics.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Dec 21 20:10:53 2009
@@ -3201,8 +3201,12 @@
     return S.Owned((Expr *)0);
   
   QualType DestType = Entity.getType().getType().getNonReferenceType();
+  // FIXME: Ugly hack around the fact that Entity.getType().getType() is not
+  // the same as Entity.getDecl()->getType() in cases involving type merging,
+  //  and we want latter when it makes sense.
   if (ResultType)
-    *ResultType = Entity.getType().getType();
+    *ResultType = Entity.getDecl() ? Entity.getDecl()->getType() :
+                                     Entity.getType().getType();
 
   Sema::OwningExprResult CurInit = S.Owned((Expr *)0);
   

Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1.cpp?rev=91881&r1=91880&r2=91881&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p1.cpp Mon Dec 21 20:10:53 2009
@@ -68,7 +68,7 @@
 };
 
 template<typename T, typename U>
-T X2<T, U>::static_member1 = 17; // expected-error{{incompatible type}}
+T X2<T, U>::static_member1 = 17; // expected-error{{cannot initialize}}
 
 template<typename T, typename U>
 U X2<T, U>::static_member2; // expected-error{{no matching}}

Modified: cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p10.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p10.cpp?rev=91881&r1=91880&r2=91881&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p10.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.explicit/p10.cpp Mon Dec 21 20:10:53 2009
@@ -20,7 +20,7 @@
 };
 
 template<typename T>
-T X0<T>::static_var = 1; // expected-error{{incompatible type}}
+T X0<T>::static_var = 1; // expected-error{{cannot initialize}}
 
 extern template struct X0<void*>;
 template struct X0<void*>; // expected-note 2{{instantiation}}

Modified: cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp?rev=91881&r1=91880&r2=91881&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp Mon Dec 21 20:10:53 2009
@@ -9,7 +9,7 @@
 // FIXME: This error message is not very good. We need to keep better
 // track of what went wrong when the implicit conversion failed to
 // give a better error message here.
-int (*pfe)(...) = &f;    // expected-error{{incompatible type initializing '<overloaded function type>', expected 'int (*)(...)'}}
+int (*pfe)(...) = &f;    // expected-error{{cannot initialize a variable of type 'int (*)(...)' with an rvalue of type '<overloaded function type>'}}
 int (&rfi)(int) = f;     // selects f(int)
 int (&rfd)(double) = f;  // selects f(double)
 

Modified: cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/aggregate-initialization.cpp?rev=91881&r1=91880&r2=91881&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/aggregate-initialization.cpp (original)
+++ cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Mon Dec 21 20:10:53 2009
@@ -22,7 +22,7 @@
   virtual void f();
 };
 
-NonAggr1 na1 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr1' with an initializer list}}
-NonAggr2 na2 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr2' with an initializer list}}
-NonAggr3 na3 = { 17 }; // expected-error{{initialization of non-aggregate type 'class NonAggr3' with an initializer list}}
-NonAggr4 na4 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr4' with an initializer list}}
+NonAggr1 na1 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr1' cannot be initialized with an initializer list}}
+NonAggr2 na2 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr2' cannot be initialized with an initializer list}}
+NonAggr3 na3 = { 17 }; // expected-error{{non-aggregate type 'class NonAggr3' cannot be initialized with an initializer list}}
+NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr4' cannot be initialized with an initializer list}}

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

==============================================================================
--- cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp (original)
+++ cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp Mon Dec 21 20:10:53 2009
@@ -13,7 +13,7 @@
 
   int a, b;
 };
-NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}}
+NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{non-aggregate type 'struct NonAggregate' cannot be initialized with an initializer list}}
 
 NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}}
 

Modified: cfe/trunk/test/SemaTemplate/typename-specifier-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/typename-specifier-2.cpp?rev=91881&r1=91880&r2=91881&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/typename-specifier-2.cpp (original)
+++ cfe/trunk/test/SemaTemplate/typename-specifier-2.cpp Mon Dec 21 20:10:53 2009
@@ -18,7 +18,7 @@
 // 'aka' telling us that we're dealing with an int**. Should we fix
 // getDesugaredType to dig through pointers and such?
 bind_metafun<add_pointer, int>::type::type ip = &i;
-bind_metafun<add_pointer, float>::type::type fp = &i; // expected-error{{incompatible type initializing 'int *', expected 'bind_metafun<add_pointer, float>::type::type' (aka 'float *')}}
+bind_metafun<add_pointer, float>::type::type fp = &i; // expected-error{{cannot initialize a variable of type 'bind_metafun<add_pointer, float>::type::type' (aka 'float *') with an rvalue of type 'int *'}}
 
 
 template<typename T>





More information about the cfe-commits mailing list