]> granicus.if.org Git - clang/commitdiff
DR408: If a static data member of incomplete array type is declared in a class
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 Nov 2013 22:40:45 +0000 (22:40 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 14 Nov 2013 22:40:45 +0000 (22:40 +0000)
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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194740 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/CXX/drs/dr4xx.cpp [new file with mode: 0644]
www/cxx_dr_status.html

index 8bbf2ff546438d3cc7d7c97687fa34fde0a225a5..9055ddac35e3577144e091db3ad7c56ab9c69be7 100644 (file)
@@ -315,6 +315,9 @@ static void computeDeclRefDependence(const ASTContext &Ctx, NamedDecl *D,
         Var->getDeclContext()->isDependentContext()) {
       ValueDependent = true;
       InstantiationDependent = true;
+      TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo();
+      if (TInfo->getType()->isIncompleteArrayType())
+        TypeDependent = true;
     }
     
     return;
diff --git a/test/CXX/drs/dr4xx.cpp b/test/CXX/drs/dr4xx.cpp
new file mode 100644 (file)
index 0000000..1d3b940
--- /dev/null
@@ -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();
+}
index 43566ccaf43c6f39b7beed50b125084026300939..cb96ff31f2a528524788b2ff18cd4154e40e3ace 100644 (file)
@@ -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>