Fix typo in enum-base disambiguation.
authorRichard Smith <richard@metafoo.co.uk>
Sun, 10 May 2020 20:39:23 +0000 (13:39 -0700)
committerRichard Smith <richard@metafoo.co.uk>
Sun, 10 May 2020 20:39:49 +0000 (13:39 -0700)
clang/lib/Parse/ParseTentative.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx98-enum.cpp [new file with mode: 0644]
clang/test/Parser/objcxx-enum.mm [new file with mode: 0644]

index fd868b8..ff941cf 100644 (file)
@@ -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.
index b4f066b..2dd53dd 100644 (file)
@@ -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 (file)
index 0000000..ed85ade
--- /dev/null
@@ -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 (file)
index 0000000..2d68aa0
--- /dev/null
@@ -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, "");