summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2017-12-11 19:44:28 +0000
committerErich Keane <erich.keane@intel.com>2017-12-11 19:44:28 +0000
commitbf5fad86db497775a4f0279b8a806d150c0fa201 (patch)
tree24595c43cd990daa265bc98933905c0b70eca8bb
parent049278c86a8799ddf77ad1402bf55a20ea2c4682 (diff)
downloadbcm5719-llvm-bf5fad86db497775a4f0279b8a806d150c0fa201.tar.gz
bcm5719-llvm-bf5fad86db497775a4f0279b8a806d150c0fa201.zip
PR35586: Relax two asserts that are overly restrictive
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). llvm-svn: 320411
-rw-r--r--clang/lib/Sema/SemaDecl.cpp6
-rw-r--r--clang/test/SemaCXX/enum-scoped.cpp5
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 48eaceeb25a..0b48a87c11d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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
diff --git a/clang/test/SemaCXX/enum-scoped.cpp b/clang/test/SemaCXX/enum-scoped.cpp
index 3114bca9347..1fcafb1dd0f 100644
--- a/clang/test/SemaCXX/enum-scoped.cpp
+++ b/clang/test/SemaCXX/enum-scoped.cpp
@@ -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.
+};
OpenPOWER on IntegriCloud