[clang] 2d3f5a6 - Fix typo in enum-base disambiguation.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Sun May 10 13:39:58 PDT 2020


Author: Richard Smith
Date: 2020-05-10T13:39:49-07:00
New Revision: 2d3f5a62de8e5d2cc25aaa49d0a00d31ed32544a

URL: https://github.com/llvm/llvm-project/commit/2d3f5a62de8e5d2cc25aaa49d0a00d31ed32544a
DIFF: https://github.com/llvm/llvm-project/commit/2d3f5a62de8e5d2cc25aaa49d0a00d31ed32544a.diff

LOG: Fix typo in enum-base disambiguation.

Added: 
    clang/test/Parser/cxx98-enum.cpp
    clang/test/Parser/objcxx-enum.mm

Modified: 
    clang/lib/Parse/ParseTentative.cpp
    clang/test/Parser/cxx0x-ambig.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index fd868b81fd09..ff941cfc441d 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -450,7 +450,7 @@ bool Parser::isEnumBase(bool AllowSemi) {
 
     // If we get to the end of the enum-base, we hit either a '{' or a ';'.
     // Don't bother checking the enumerator-list.
-    if (Tok.is(tok::colon) || (AllowSemi && Tok.is(tok::semi)))
+    if (Tok.is(tok::l_brace) || (AllowSemi && Tok.is(tok::semi)))
       return true;
 
     // A second decl-specifier unambiguously indicatges an enum-base.

diff  --git a/clang/test/Parser/cxx0x-ambig.cpp b/clang/test/Parser/cxx0x-ambig.cpp
index b4f066b04a5f..2dd53dd6daab 100644
--- a/clang/test/Parser/cxx0x-ambig.cpp
+++ b/clang/test/Parser/cxx0x-ambig.cpp
@@ -86,6 +86,8 @@ namespace bitfield {
   // be ill-formed. It cannot be an elaborated-type-specifier.
   struct S {
     enum : undeclared_type { v = 0 }; // expected-error {{unknown type name 'undeclared_type'}}
+    enum E : undeclared_type { w = 0 }; // expected-error {{unknown type name 'undeclared_type'}}
+    enum X : undeclared_type { x = 0 }; // expected-error {{unknown type name 'undeclared_type'}}
   };
 }
 

diff  --git a/clang/test/Parser/cxx98-enum.cpp b/clang/test/Parser/cxx98-enum.cpp
new file mode 100644
index 000000000000..ed85adea3c6e
--- /dev/null
+++ b/clang/test/Parser/cxx98-enum.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++98 -verify %s
+
+enum E {};
+enum F {};
+
+struct A {
+  // OK, this is an enumeration bit-field.
+  enum E : int(0);
+  enum F : int{0}; // expected-error {{expected '(' for function-style cast}}
+};

diff  --git a/clang/test/Parser/objcxx-enum.mm b/clang/test/Parser/objcxx-enum.mm
new file mode 100644
index 000000000000..2d68aa047a8a
--- /dev/null
+++ b/clang/test/Parser/objcxx-enum.mm
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -std=c++98 %s
+// expected-no-diagnostics
+
+// Objective-C allows C++11 enumerations in C++98 mode. We disambiguate in
+// order to make this a backwards-compatible extension.
+struct A {
+  enum E : int{a}; // OK, enum definition
+  enum E : int(a); // OK, bit-field declaration
+};
+_Static_assert(A::a == 0, "");


        


More information about the cfe-commits mailing list