summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaTemplate.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-22 16:17:30 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-22 16:17:30 +0000
commit959d5a0cbd78f8e658a8ec203e675ddb164ee879 (patch)
tree033102b117488805f969cc02aaf6c119883e64fc /clang/lib/Sema/SemaTemplate.cpp
parent33eee34230986a7fd339383933db93801790a29e (diff)
downloadbcm5719-llvm-959d5a0cbd78f8e658a8ec203e675ddb164ee879.tar.gz
bcm5719-llvm-959d5a0cbd78f8e658a8ec203e675ddb164ee879.zip
Implement support for variable length arrays in C++. VLAs are limited
in several important ways: - VLAs of non-POD types are not permitted. - VLAs cannot be used in conjunction with C++ templates. These restrictions are intended to keep VLAs out of the parts of the C++ type system where they cause the most trouble. Fixes PR5678 and <rdar://problem/8013618>. llvm-svn: 104443
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 8ff637f2d11..ac77c11b951 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -553,6 +553,13 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) {
// assume that it is well-formed.
T->isDependentType())
return T;
+ // We don't allow variably-modified types as the type of non-type template
+ // parameters.
+ else if (T->isVariablyModifiedType()) {
+ Diag(Loc, diag::err_variably_modified_nontype_template_param)
+ << T;
+ return QualType();
+ }
// C++ [temp.param]p8:
//
// A non-type template-parameter of type "array of T" or
@@ -564,7 +571,7 @@ Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) {
else if (T->isFunctionType())
// FIXME: Keep the type prior to promotion?
return Context.getPointerType(T);
-
+
Diag(Loc, diag::err_template_nontype_parm_bad_type)
<< T;
@@ -2354,7 +2361,8 @@ bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param,
// compounded from any of these types shall not be used as a
// template-argument for a template type-parameter.
//
- // FIXME: Perform the recursive and no-linkage type checks.
+ // FIXME: Perform the unnamed type check.
+ SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();
const TagType *Tag = 0;
if (const EnumType *EnumT = Arg->getAs<EnumType>())
Tag = EnumT;
@@ -2366,12 +2374,14 @@ bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param,
<< QualType(Tag, 0) << SR;
} else if (Tag && !Tag->getDecl()->getDeclName() &&
!Tag->getDecl()->getTypedefForAnonDecl()) {
- SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();
Diag(SR.getBegin(), diag::err_template_arg_unnamed_type) << SR;
Diag(Tag->getDecl()->getLocation(), diag::note_template_unnamed_type_here);
return true;
+ } else if (Arg->isVariablyModifiedType()) {
+ Diag(SR.getBegin(), diag::err_variably_modified_template_arg)
+ << Arg;
+ return true;
} else if (Context.hasSameUnqualifiedType(Arg, Context.OverloadTy)) {
- SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();
return Diag(SR.getBegin(), diag::err_template_arg_overload_type) << SR;
}
OpenPOWER on IntegriCloud