Make sure that we instantiate variably modified types, even if they
aren't dependent. Fixes <rdar://problem/8020206>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104511 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 0e4dfcb..1adf594 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -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();
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 10d2bb1..834b86d 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -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) {