[cfe-commits] r104511 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaCXX/c99-variable-length-array.cpp
Douglas Gregor
dgregor at apple.com
Mon May 24 10:22:01 PDT 2010
Author: dgregor
Date: Mon May 24 12:22:01 2010
New Revision: 104511
URL: http://llvm.org/viewvc/llvm-project?rev=104511&view=rev
Log:
Make sure that we instantiate variably modified types, even if they
aren't dependent. Fixes <rdar://problem/8020206>.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=104511&r1=104510&r2=104511&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon May 24 12:22:01 2010
@@ -627,7 +627,7 @@
if (T.isNull())
return true;
- if (T->isDependentType())
+ if (T->isDependentType() || T->isVariablyModifiedType())
return false;
getSema().MarkDeclarationsReferencedInType(Loc, T);
@@ -942,7 +942,8 @@
"Cannot perform an instantiation without some context on the "
"instantiation stack");
- if (!T->getType()->isDependentType())
+ if (!T->getType()->isDependentType() &&
+ !T->getType()->isVariablyModifiedType())
return T;
TemplateInstantiator Instantiator(*this, Args, Loc, Entity);
@@ -957,8 +958,9 @@
"Cannot perform an instantiation without some context on the "
"instantiation stack");
- // If T is not a dependent type, there is nothing to do.
- if (!T->isDependentType())
+ // If T is not a dependent type or a variably-modified type, there
+ // is nothing to do.
+ if (!T->isDependentType() && !T->isVariablyModifiedType())
return T;
TemplateInstantiator Instantiator(*this, TemplateArgs, Loc, Entity);
@@ -966,7 +968,7 @@
}
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
- if (T->getType()->isDependentType())
+ if (T->getType()->isDependentType() || T->getType()->isVariablyModifiedType())
return true;
TypeLoc TL = T->getTypeLoc();
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=104511&r1=104510&r2=104511&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon May 24 12:22:01 2010
@@ -184,7 +184,8 @@
Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
bool Invalid = false;
TypeSourceInfo *DI = D->getTypeSourceInfo();
- if (DI->getType()->isDependentType()) {
+ if (DI->getType()->isDependentType() ||
+ DI->getType()->isVariablyModifiedType()) {
DI = SemaRef.SubstType(DI, TemplateArgs,
D->getLocation(), D->getDeclName());
if (!DI) {
@@ -438,7 +439,8 @@
Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
bool Invalid = false;
TypeSourceInfo *DI = D->getTypeSourceInfo();
- if (DI->getType()->isDependentType()) {
+ if (DI->getType()->isDependentType() ||
+ DI->getType()->isVariablyModifiedType()) {
DI = SemaRef.SubstType(DI, TemplateArgs,
D->getLocation(), D->getDeclName());
if (!DI) {
Modified: cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp?rev=104511&r1=104510&r2=104511&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp (original)
+++ cfe/trunk/test/SemaCXX/c99-variable-length-array.cpp Mon May 24 12:22:01 2010
@@ -90,3 +90,13 @@
struct edge_info edgeInfo[x]; // expected-warning{{variable length arrays are a C99 feature, accepted as an extension}}
}
}
+
+namespace rdar8020206 {
+ template<typename T>
+ void f(int i) {
+ const unsigned value = i;
+ int array[value * i]; // expected-warning 2{{variable length arrays are a C99 feature, accepted as an extension}}
+ }
+
+ template void f<int>(int); // expected-note{{instantiation of}}
+}
More information about the cfe-commits
mailing list