Add tests checking for unexpanded parameter packs in declarations that

occur within statements. Teach Sema::ActOnExceptionDeclarator() to
check for unexpanded parameter packs in the exception type.

llvm-svn: 121984
This commit is contained in:
Douglas Gregor 2010-12-16 17:48:04 +00:00
parent 03fcccbb47
commit 72772f65ec
4 changed files with 38 additions and 7 deletions

View File

@ -1825,25 +1825,25 @@ def err_unexpanded_parameter_pack_0 : Error<
"%select{expression|base type|declaration type|data member type|bit-field "
"size|static assertion|fixed underlying type|enumerator value|"
"using declaration|friend declaration|qualifier|initializer|default argument|"
"non-type template parameter type}0 "
"non-type template parameter type|exception type}0 "
"contains an unexpanded parameter pack">;
def err_unexpanded_parameter_pack_1 : Error<
"%select{expression|base type|declaration type|data member type|bit-field "
"size|static assertion|fixed underlying type|enumerator value|"
"using declaration|friend declaration|qualifier|initializer|default argument|"
"non-type template parameter type}0 "
"non-type template parameter type|exception type}0 "
"contains unexpanded parameter pack %1">;
def err_unexpanded_parameter_pack_2 : Error<
"%select{expression|base type|declaration type|data member type|bit-field "
"size|static assertion|fixed underlying type|enumerator value|"
"using declaration|friend declaration|qualifier|initializer|default argument|"
"non-type template parameter type}0 "
"non-type template parameter type|exception type}0 "
"contains unexpanded parameter packs %1 and %2">;
def err_unexpanded_parameter_pack_3_or_more : Error<
"%select{expression|base type|declaration type|data member type|bit-field "
"size|static assertion|fixed underlying type|enumerator value|"
"using declaration|friend declaration|qualifier|initializer|default argument|"
"non-type template parameter type}0 "
"non-type template parameter type|exception type}0 "
"contains unexpanded parameter packs %1, %2, ...">;
def err_unexpected_typedef : Error<

View File

@ -3175,7 +3175,10 @@ public:
UPPC_DefaultArgument,
/// \brief The type of a non-type template parameter.
UPPC_NonTypeTemplateParameterType
UPPC_NonTypeTemplateParameterType,
/// \brief The type of an exception.
UPPC_ExceptionType
};
/// \brief If the given type contains an unexpanded parameter pack,

View File

@ -6138,9 +6138,18 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S,
/// handler.
Decl *Sema::ActOnExceptionDeclarator(Scope *S, Declarator &D) {
TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
bool Invalid = D.isInvalidType();
// Check for unexpanded parameter packs.
if (TInfo && DiagnoseUnexpandedParameterPack(D.getIdentifierLoc(), TInfo,
UPPC_ExceptionType)) {
TInfo = Context.getTrivialTypeSourceInfo(Context.IntTy,
D.getIdentifierLoc());
Invalid = true;
}
QualType ExDeclType = TInfo->getType();
bool Invalid = D.isInvalidType();
IdentifierInfo *II = D.getIdentifier();
if (NamedDecl *PrevDecl = LookupSingleName(S, II, D.getIdentifierLoc(),
LookupOrdinaryName,

View File

@ -103,7 +103,7 @@ void TestPPNameFunc(int i) {
f(static_cast<Types>(i)); // expected-error{{expression contains unexpanded parameter pack 'Types'}}
}
// FIXME: Test for unexpanded parameter packs in declarations.
// Test for unexpanded parameter packs in declarations.
// FIXME: Attributes?
template<typename T, typename... Types>
struct TestUnexpandedDecls : T{
@ -144,8 +144,27 @@ struct TestUnexpandedDecls : T{
template<Types value> // expected-error{{non-type template parameter type contains unexpanded parameter pack 'Types'}}
struct non_type_template_param_type;
void decls_in_stmts() {
Types t; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
for (Types *t = 0; ; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
for (; Types *t = 0; ) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
switch(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
while(Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
if (Types *t = 0) { } // expected-error{{declaration type contains unexpanded parameter pack 'Types'}}
try {
} catch (Types*) { // expected-error{{exception type contains unexpanded parameter pack 'Types'}}
}
}
};
// FIXME: Test for unexpanded parameter packs in each of the statements.
// FIXME: Once we have template argument deduction, we can test
// unexpanded parameter packs in partial specializations.
// template<typename ...Types>
// struct TestUnexpandedDecls<int, Types>;
// Test for diagnostics in the presence of multiple unexpanded
// parameter packs.
template<typename T, typename U> struct pair;