diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-05-23 19:57:01 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-05-23 19:57:01 +0000 |
| commit | a09387df9ffbe0849288b6ba5ce9a31c0829eed5 (patch) | |
| tree | 62ddf7fccee11b545778d1c19ea979882a26b82c /clang/lib | |
| parent | 2788782164db1a55d40f18a43e11e58904aeb836 (diff) | |
| download | bcm5719-llvm-a09387df9ffbe0849288b6ba5ce9a31c0829eed5.tar.gz bcm5719-llvm-a09387df9ffbe0849288b6ba5ce9a31c0829eed5.zip | |
It turns out that people love using VLAs in templates, too. Weaken our
VLA restrictions so that one can use VLAs in templates (even
accidentally), but not as part of a non-type template parameter (which
would be very bad).
llvm-svn: 104471
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/AST/Type.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 15 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 14 |
3 files changed, 16 insertions, 16 deletions
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index a7527e7ccfa..1aab65ebec5 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -277,6 +277,9 @@ QualType Type::getPointeeType() const { /// array types and types that contain variable array types in their /// declarator bool Type::isVariablyModifiedType() const { + // FIXME: We should really keep a "variably modified" bit in Type, rather + // than walking the type hierarchy to recompute it. + // A VLA is a variably modified type. if (isVariableArrayType()) return true; diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index ecac7a212a5..307be9d7865 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -534,6 +534,14 @@ void Sema::ActOnTypeParameterDefault(DeclPtrTy TypeParam, /// otherwise, produces a diagnostic and returns a NULL type. QualType Sema::CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc) { + // We don't allow variably-modified types as the type of non-type template + // parameters. + if (T->isVariablyModifiedType()) { + Diag(Loc, diag::err_variably_modified_nontype_template_param) + << T; + return QualType(); + } + // C++ [temp.param]p4: // // A non-type template-parameter shall have one of the following @@ -553,13 +561,6 @@ 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 diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index b25d0763591..ea2b2e68125 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -716,15 +716,11 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, << Context.getBaseElementType(T); return QualType(); } - // Prohibit the use of VLAs in template instantiations, since we don't - // want them to accidentally be used. This means that we handle VLAs in - // C-like contexts, but still ban them from C++-specific contexts. - // And, since we check template definitions early, prohibit them there, - // too. - else if (CurContext->isDependentContext() || - ActiveTemplateInstantiations.size()) - Diag(Loc, diag::err_vla_in_template) - << !CurContext->isDependentContext(); + // Prohibit the use of VLAs during template argument deduction. + else if (isSFINAEContext()) { + Diag(Loc, diag::err_vla_in_sfinae); + return QualType(); + } // Just extwarn about VLAs. else Diag(Loc, diag::ext_vla); |

