]> granicus.if.org Git - clang/commitdiff
Check for unexpanded parameter packs in enumeration types and enumerators.
authorDouglas Gregor <dgregor@apple.com>
Thu, 16 Dec 2010 00:24:44 +0000 (00:24 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 16 Dec 2010 00:24:44 +0000 (00:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121928 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
test/CXX/temp/temp.decls/temp.variadic/p5.cpp

index 7cdfab6200daabb21169ecfc5e84a5f53258e82a..f6e6f075b6c79149cdc09616cd57a08763200214 100644 (file)
@@ -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<
index 07a7be298e536775d5378e86837ae35491f05b5f..c375b848085f573dd0c3970d766916f8a92cd17b 100644 (file)
@@ -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,
index 5704cb5ad46949070f2cdb97f823e11cbb51e035..95c3b998019ef25bd49f0a15486aedd4e80a4fea 100644 (file)
@@ -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;
index 52a619010d3b7806eff8febabeec4f513a383603..1f56c889a6eae4c232316cc942ffa22887e7276c 100644 (file)
@@ -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