r337738 - Update to -r337585, allow scoped enum inits in -pedantic

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 23 14:08:13 PDT 2018


Author: erichkeane
Date: Mon Jul 23 14:08:13 2018
New Revision: 337738

URL: http://llvm.org/viewvc/llvm-project?rev=337738&view=rev
Log:
Update to -r337585, allow scoped enum inits in -pedantic

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/PR38235.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=337738&r1=337737&r2=337738&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jul 23 14:08:13 2018
@@ -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;

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=337738&r1=337737&r2=337738&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Mon Jul 23 14:08:13 2018
@@ -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())

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=337738&r1=337737&r2=337738&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 23 14:08:13 2018
@@ -11165,6 +11165,9 @@ void Sema::AddInitializerToDecl(Decl *Re
         ; // 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.

Modified: cfe/trunk/test/SemaCXX/PR38235.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR38235.cpp?rev=337738&r1=337737&r2=337738&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/PR38235.cpp (original)
+++ cfe/trunk/test/SemaCXX/PR38235.cpp Mon Jul 23 14:08:13 2018
@@ -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;
+};




More information about the cfe-commits mailing list