]> granicus.if.org Git - clang/commitdiff
PR35586: Relax two asserts that are overly restrictive
authorErich Keane <erich.keane@intel.com>
Mon, 11 Dec 2017 19:44:28 +0000 (19:44 +0000)
committerErich Keane <erich.keane@intel.com>
Mon, 11 Dec 2017 19:44:28 +0000 (19:44 +0000)
The two asserts are too aggressive.  In C++  mode, an
enum is NOT considered an integral type, but an enum value
is allowed to be an enum.  This patch relaxes the two asserts
to allow the enum value as well (as typechecking does).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320411 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/enum-scoped.cpp

index 48eaceeb25a6b61eccd4e1c6369516e2f4bc1241..0b48a87c11d1e6cd59793ce2808bb7c8b4708920 100644 (file)
@@ -15217,7 +15217,8 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
 static bool isRepresentableIntegerValue(ASTContext &Context,
                                         llvm::APSInt &Value,
                                         QualType T) {
-  assert(T->isIntegralType(Context) && "Integral type required!");
+  assert((T->isIntegralType(Context) || T->isEnumeralType()) &&
+         "Integral type required!");
   unsigned BitWidth = Context.getIntWidth(T);
 
   if (Value.isUnsigned() || Value.isNonNegative()) {
@@ -15233,7 +15234,8 @@ static bool isRepresentableIntegerValue(ASTContext &Context,
 static QualType getNextLargerIntegralType(ASTContext &Context, QualType T) {
   // FIXME: Int128/UInt128 support, which also needs to be introduced into
   // enum checking below.
-  assert(T->isIntegralType(Context) && "Integral type required!");
+  assert((T->isIntegralType(Context) ||
+         T->isEnumeralType()) && "Integral type required!");
   const unsigned NumTypes = 4;
   QualType SignedIntegralTypes[NumTypes] = {
     Context.ShortTy, Context.IntTy, Context.LongTy, Context.LongLongTy
index 3114bca9347dfbb807c6ced0ec22904c202e3e3c..1fcafb1dd0fdcff0858628120d3b0e7c69206d38 100644 (file)
@@ -309,3 +309,8 @@ namespace test11 {
 
   bool f() { return !f1(); } // expected-error {{invalid argument type 'test11::E2' (aka 'test11::E') to unary expression}}
 }
+
+namespace PR35586 {
+  enum C { R, G, B };
+  enum B { F = (enum C) -1, T}; // this should compile cleanly, it used to assert.
+};