[cfe-commits] r147023 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/PCH/chain-cxx.cpp test/SemaTemplate/instantiate-declref-ice.cpp

Richard Smith richard-llvm at metafoo.co.uk
Tue Dec 20 16:25:33 PST 2011


Author: rsmith
Date: Tue Dec 20 18:25:33 2011
New Revision: 147023

URL: http://llvm.org/viewvc/llvm-project?rev=147023&view=rev
Log:
C++ constant expression handling: eagerly instantiate static const integral data
members of class templates so that their values can be used in ICEs. This
required reverting r105465, to get such instantiated members to be included in
serialized ASTs.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/PCH/chain-cxx.cpp
    cfe/trunk/test/SemaTemplate/instantiate-declref-ice.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=147023&r1=147022&r2=147023&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Dec 20 18:25:33 2011
@@ -9526,7 +9526,12 @@
         // This is a modification of an existing AST node. Notify listeners.
         if (ASTMutationListener *L = getASTMutationListener())
           L->StaticDataMemberInstantiated(Var);
-        PendingInstantiations.push_back(std::make_pair(Var, Loc));
+        QualType T = Var->getType();
+        if (T.isConstQualified() && !T.isVolatileQualified() &&
+            T->isIntegralOrEnumerationType())
+          InstantiateStaticDataMemberDefinition(Loc, Var);
+        else
+          PendingInstantiations.push_back(std::make_pair(Var, Loc));
       }
     }
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=147023&r1=147022&r2=147023&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Dec 20 18:25:33 2011
@@ -359,8 +359,7 @@
   SemaRef.CheckVariableDeclaration(Var, Previous);
 
   if (D->isOutOfLine()) {
-    if (!D->isStaticDataMember())
-      D->getLexicalDeclContext()->addDecl(Var);
+    D->getLexicalDeclContext()->addDecl(Var);
     Owner->makeDeclVisibleInContext(Var);
   } else {
     Owner->addDecl(Var);

Modified: cfe/trunk/test/PCH/chain-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-cxx.cpp?rev=147023&r1=147022&r2=147023&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-cxx.cpp (original)
+++ cfe/trunk/test/PCH/chain-cxx.cpp Tue Dec 20 18:25:33 2011
@@ -38,9 +38,12 @@
 template <typename T>
 struct TS3 {
   static const int value = 0;
+  static const int value2;
 };
 template <typename T>
 const int TS3<T>::value;
+template <typename T>
+const int TS3<T>::value2 = 1;
 // Instantiate struct, but not value.
 struct instantiate : TS3<int> {};
 
@@ -96,8 +99,9 @@
 struct A { };
 struct B : A { };
 
-// Instantiate TS3's member.
+// Instantiate TS3's members.
 static const int ts3m1 = TS3<int>::value;
+extern int arr[TS3<int>::value2];
 
 // Redefinition of typedef
 typedef int Integer;
@@ -132,6 +136,7 @@
 
 // Should have remembered that there is a definition.
 static const int ts3m2 = TS3<int>::value;
+int arr[TS3<int>::value2];
 
 //===----------------------------------------------------------------------===//
 #endif

Modified: cfe/trunk/test/SemaTemplate/instantiate-declref-ice.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-declref-ice.cpp?rev=147023&r1=147022&r2=147023&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-declref-ice.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-declref-ice.cpp Tue Dec 20 18:25:33 2011
@@ -31,4 +31,4 @@
 template<typename T>
 const unsigned X1<T>::value = sizeof(T);
 
-int array3[X1<int>::value == sizeof(int)? 1 : -1]; // expected-error{{variable length array declaration not allowed at file scope}}
+int array3[X1<int>::value == sizeof(int)? 1 : -1];





More information about the cfe-commits mailing list