]> granicus.if.org Git - clang/commitdiff
Update to -r337585, allow scoped enum inits in -pedantic
authorErich Keane <erich.keane@intel.com>
Mon, 23 Jul 2018 21:08:13 +0000 (21:08 +0000)
committerErich Keane <erich.keane@intel.com>
Mon, 23 Jul 2018 21:08:13 +0000 (21:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337738 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Type.h
lib/AST/Type.cpp
lib/Sema/SemaDecl.cpp
test/SemaCXX/PR38235.cpp

index cbdbc529f7396a8794bd911ccf7dce12bb144f57..c692707847a69f8a2817c248e3b5a2aa598280d2 100644 (file)
@@ -1784,6 +1784,9 @@ public:
   /// isComplexIntegerType() can be used to test for complex integers.
   bool isIntegerType() const;     // C99 6.2.5p17 (int, char, bool, enum)
   bool isEnumeralType() const;
+
+  /// Determine whether this type is a scoped enumeration type.
+  bool isScopedEnumeralType() const;
   bool isBooleanType() const;
   bool isCharType() const;
   bool isWideCharType() const;
index cd30bc16d05bffa352f0286e624de62934e5c4ec..fad8c0d1c6b275bbc38f25067b161fb3f329635e 100644 (file)
@@ -481,6 +481,12 @@ bool Type::isComplexIntegerType() const {
   return getAsComplexIntegerType();
 }
 
+bool Type::isScopedEnumeralType() const {
+  if (const auto *ET = getAs<EnumType>())
+    return ET->getDecl()->isScoped();
+  return false;
+}
+
 const ComplexType *Type::getAsComplexIntegerType() const {
   if (const auto *Complex = getAs<ComplexType>())
     if (Complex->getElementType()->isIntegerType())
index e91e9d3ac16302e90e5655d731f7ca5c99477f4f..55542828f783921156dec75f630ec65e42ddd8ae 100644 (file)
@@ -11165,6 +11165,9 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
         ; // Nothing to check.
       else if (Init->isIntegerConstantExpr(Context, &Loc))
         ; // Ok, it's an ICE!
+      else if (Init->getType()->isScopedEnumeralType() &&
+               Init->isCXX11ConstantExpr(Context))
+        ; // Ok, it is a scoped-enum constant expression.
       else if (Init->isEvaluatable(Context)) {
         // If we can constant fold the initializer through heroics, accept it,
         // but report this as a use of an extension for -pedantic.
index 11874c837bcc5b4cc2bb2063108d946cba163f1b..c3fd38ab04d6a117bb200922e9c32ebf314117ef 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 
 enum class E { Foo, Bar = 97119 };
 
@@ -12,3 +12,9 @@ void switch_me(E e) {
       break;
   }
 }
+
+enum class E2;
+
+struct S {
+  static const E e = E::Foo;
+};