From: Richard Smith Date: Thu, 14 Nov 2013 22:40:45 +0000 (+0000) Subject: DR408: If a static data member of incomplete array type is declared in a class X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=418220b209ed67a5cc6802d367a9a994d7225e04;p=clang 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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194740 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 8bbf2ff546..9055ddac35 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -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 index 0000000000..1d3b94064c --- /dev/null +++ b/test/CXX/drs/dr4xx.cpp @@ -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 void g() { int arr[N != 1 ? 1 : -1]; } + template<> void g<2>() { } + + template struct S { + static int i[]; + void f(); + }; + template int S::i[] = { 1 }; + + template void S::f() { + g(); + } + template<> int S::i[] = { 1, 2 }; + template void S::f(); // uses g<2>(), not g<1>(). + + + template struct R { + static int arr[]; + void f(); + }; + template int R::arr[1]; + template void R::f() { + int arr[sizeof(arr) != sizeof(int) ? 1 : -1]; + } + template<> int R::arr[2]; + template void R::f(); +} diff --git a/www/cxx_dr_status.html b/www/cxx_dr_status.html index 43566ccaf4..cb96ff31f2 100644 --- a/www/cxx_dr_status.html +++ b/www/cxx_dr_status.html @@ -2488,7 +2488,7 @@ of class templates 408 CD2 sizeof applied to unknown-bound array static data member of template - Unknown + SVN 409