diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-16 00:24:44 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-16 00:24:44 +0000 |
commit | 2b988fd7451bd59e9598c84f5bbc9425c45e28c0 (patch) | |
tree | 6f1b449854777009dc41f1d8de500b86095fdda3 /clang | |
parent | c7a2c053ff4175ce99f7686706baade829fbe6fd (diff) | |
download | bcm5719-llvm-2b988fd7451bd59e9598c84f5bbc9425c45e28c0.tar.gz bcm5719-llvm-2b988fd7451bd59e9598c84f5bbc9425c45e28c0.zip |
Check for unexpanded parameter packs in enumeration types and enumerators.
llvm-svn: 121928
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 10 | ||||
-rw-r--r-- | clang/include/clang/Sema/Sema.h | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp | 4 |
4 files changed, 25 insertions, 6 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 7cdfab6200d..f6e6f075b6c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1823,19 +1823,19 @@ def note_template_parameter_pack_here : Note< def err_unexpanded_parameter_pack_0 : Error< "%select{expression|base type|declaration type|data member type|bit-field " - "size|static assertion}0 " - "contains unexpanded parameter pack">; + "size|static assertion|fixed underlying type|enumerator value}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}0 " + "size|static assertion|fixed underlying type|enumerator value}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}0 " + "size|static assertion|fixed underlying type|enumerator value}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}0 " + "size|static assertion|fixed underlying type|enumerator value}0 " "contains unexpanded parameter packs %1, %2, ...">; def err_unexpected_typedef : Error< diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 07a7be298e5..c375b848085 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -3151,7 +3151,13 @@ public: UPPC_BitFieldWidth, /// \brief The expression in a static assertion. - UPPC_StaticAssertExpression + UPPC_StaticAssertExpression, + + /// \brief The fixed underlying type of an enumeration. + UPPC_FixedUnderlyingType, + + /// \brief The enumerator value. + UPPC_EnumeratorValue }; /// \brief If the given type contains an unexpanded parameter pack, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5704cb5ad46..95c3b998019 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5771,6 +5771,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // Recover by falling back to int. EnumUnderlying = Context.IntTy.getTypePtr(); } + + if (DiagnoseUnexpandedParameterPack(UnderlyingLoc, TI, + UPPC_FixedUnderlyingType)) + EnumUnderlying = Context.IntTy.getTypePtr(); + } else if (getLangOptions().Microsoft) // Microsoft enums are always of int type. EnumUnderlying = Context.IntTy.getTypePtr(); @@ -7319,6 +7324,10 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, unsigned IntWidth = Context.Target.getIntWidth(); llvm::APSInt EnumVal(IntWidth); QualType EltTy; + + if (Val && DiagnoseUnexpandedParameterPack(Val, UPPC_EnumeratorValue)) + Val = 0; + if (Val) { if (Enum->isDependentType() || Val->isTypeDependent()) EltTy = Context.DependentTy; diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp index 52a619010d3..1f56c889a6e 100644 --- a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp @@ -112,6 +112,10 @@ struct TestUnexpandedDecls { static Types static_data_member; // expected-error{{declaration type contains unexpanded parameter pack 'Types'}} unsigned bit_field : static_cast<Types>(0); // expected-error{{bit-field size contains unexpanded parameter pack 'Types'}} static_assert(static_cast<Types>(0), "Boom"); // expected-error{{static assertion contains unexpanded parameter pack 'Types'}} + + enum E0 : Types { // expected-error{{fixed underlying type contains unexpanded parameter pack 'Types'}} + EnumValue = static_cast<Types>(0) // expected-error{{enumerator value contains unexpanded parameter pack 'Types'}} + }; }; // Test for diagnostics in the presence of multiple unexpanded |