Make sure that we instantiate variably modified types, even if they

aren't dependent. Fixes <rdar://problem/8020206>.

llvm-svn: 104511
This commit is contained in:
Douglas Gregor 2010-05-24 17:22:01 +00:00
parent 8d042c0269
commit 5a5073e4d6
3 changed files with 21 additions and 7 deletions

View File

@ -627,7 +627,7 @@ bool TemplateInstantiator::AlreadyTransformed(QualType T) {
if (T.isNull())
return true;
if (T->isDependentType())
if (T->isDependentType() || T->isVariablyModifiedType())
return false;
getSema().MarkDeclarationsReferencedInType(Loc, T);
@ -942,7 +942,8 @@ TypeSourceInfo *Sema::SubstType(TypeSourceInfo *T,
"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 @@ QualType Sema::SubstType(QualType T,
"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 @@ QualType Sema::SubstType(QualType T,
}
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
if (T->getType()->isDependentType())
if (T->getType()->isDependentType() || T->getType()->isVariablyModifiedType())
return true;
TypeLoc TL = T->getTypeLoc();

View File

@ -184,7 +184,8 @@ TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
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::VisitVarDecl(VarDecl *D) {
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) {

View File

@ -90,3 +90,13 @@ namespace PR7206 {
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}}
}