r194740 - DR408: If a static data member of incomplete array type is declared in a class

Richard Smith richard-llvm at metafoo.co.uk
Thu Nov 14 14:40:45 PST 2013


Author: rsmith
Date: Thu Nov 14 16:40:45 2013
New Revision: 194740

URL: http://llvm.org/viewvc/llvm-project?rev=194740&view=rev
Log:
DR408: If a static data member of incomplete array type is declared in a class
template, that member has a dependent type (even if we can see the definition
of the member of the primary template), because the array size could change in
a member specialization.

Patch by Karthik Bhat!

Added:
    cfe/trunk/test/CXX/drs/dr4xx.cpp
Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/www/cxx_dr_status.html

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=194740&r1=194739&r2=194740&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Nov 14 16:40:45 2013
@@ -315,6 +315,9 @@ static void computeDeclRefDependence(con
         Var->getDeclContext()->isDependentContext()) {
       ValueDependent = true;
       InstantiationDependent = true;
+      TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo();
+      if (TInfo->getType()->isIncompleteArrayType())
+        TypeDependent = true;
     }
     
     return;

Added: cfe/trunk/test/CXX/drs/dr4xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr4xx.cpp?rev=194740&view=auto
==============================================================================
--- cfe/trunk/test/CXX/drs/dr4xx.cpp (added)
+++ cfe/trunk/test/CXX/drs/dr4xx.cpp Thu Nov 14 16:40:45 2013
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// expected-no-diagnostics
+
+namespace dr408 { // dr408: 3.4
+  template<int N> void g() { int arr[N != 1 ? 1 : -1]; }
+  template<> void g<2>() { }
+
+  template<typename T> struct S {
+    static int i[];
+    void f();
+  };
+  template<typename T> int S<T>::i[] = { 1 };
+
+  template<typename T> void S<T>::f() {
+    g<sizeof (i) / sizeof (int)>();
+  }
+  template<> int S<int>::i[] = { 1, 2 };
+  template void S<int>::f(); // uses g<2>(), not g<1>().
+
+
+  template<typename T> struct R {
+    static int arr[];
+    void f();
+  };
+  template<typename T> int R<T>::arr[1];
+  template<typename T> void R<T>::f() {
+    int arr[sizeof(arr) != sizeof(int) ? 1 : -1];
+  }
+  template<> int R<int>::arr[2];
+  template void R<int>::f();
+}

Modified: cfe/trunk/www/cxx_dr_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_dr_status.html?rev=194740&r1=194739&r2=194740&view=diff
==============================================================================
--- cfe/trunk/www/cxx_dr_status.html (original)
+++ cfe/trunk/www/cxx_dr_status.html Thu Nov 14 16:40:45 2013
@@ -2488,7 +2488,7 @@ of class templates</td>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#408">408</a></td>
     <td>CD2</td>
     <td>sizeof applied to unknown-bound array static data member of template</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="svn" align="center">SVN</td>
   </tr>
   <tr>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#409">409</a></td>





More information about the cfe-commits mailing list