[clang] [Clang][Parser] Report error when attribute missing ]] followed by ;; (PR #187580)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 19 15:02:33 PDT 2026
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/187580
>From 7bed20f61a35a14151de2d8db263f87fe4c5a8b2 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Thu, 19 Mar 2026 21:12:03 +0100
Subject: [PATCH] [Clang][Parser] Report error when attribute missing `]]`
followed by `;;`
---
clang/lib/Parse/ParseDeclCXX.cpp | 7 -------
.../cxx-attributes-missing-closing-in-switch.cpp | 15 +++++++++++++++
.../Parser/cxx-attributes-missing-closing.cpp | 5 +++++
...attributes-missing-with-semi-bfore-closing.cpp | 5 +++++
4 files changed, 25 insertions(+), 7 deletions(-)
create mode 100644 clang/test/Parser/cxx-attributes-missing-closing-in-switch.cpp
create mode 100644 clang/test/Parser/cxx-attributes-missing-closing.cpp
create mode 100644 clang/test/Parser/cxx-attributes-missing-with-semi-bfore-closing.cpp
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 274c354d59808..c759d37815903 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -4681,13 +4681,6 @@ void Parser::ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
Diag(Tok, diag::err_cxx11_attribute_forbids_ellipsis) << AttrName;
}
- // If we hit an error and recovered by parsing up to a semicolon, eat the
- // semicolon and don't issue further diagnostics about missing brackets.
- if (Tok.is(tok::semi)) {
- ConsumeToken();
- return;
- }
-
SourceLocation CloseLoc = Tok.getLocation();
if (ExpectAndConsume(tok::r_square))
SkipUntil(tok::r_square);
diff --git a/clang/test/Parser/cxx-attributes-missing-closing-in-switch.cpp b/clang/test/Parser/cxx-attributes-missing-closing-in-switch.cpp
new file mode 100644
index 0000000000000..55b7c0477d938
--- /dev/null
+++ b/clang/test/Parser/cxx-attributes-missing-closing-in-switch.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-note at +1 {{to match this '{'}}
+void a(int i) {
+ switch(i) {
+ case 1:
+ // expected-error at +2 {{expected ']'}}
+ // expected-error at +3 {{expected ']'}}
+ [[fallthrough;;
+ case 2:
+ ;
+ };
+ // expected-error at +2 {{expected statement}}
+ // expected-error at +1 {{expected '}'}}
+}
diff --git a/clang/test/Parser/cxx-attributes-missing-closing.cpp b/clang/test/Parser/cxx-attributes-missing-closing.cpp
new file mode 100644
index 0000000000000..87219eec75422
--- /dev/null
+++ b/clang/test/Parser/cxx-attributes-missing-closing.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-error at +2 2 {{expected ']'}}
+// expected-error at +1 {{expected external declaration}}
+[[assume0;;
diff --git a/clang/test/Parser/cxx-attributes-missing-with-semi-bfore-closing.cpp b/clang/test/Parser/cxx-attributes-missing-with-semi-bfore-closing.cpp
new file mode 100644
index 0000000000000..0a45413159e56
--- /dev/null
+++ b/clang/test/Parser/cxx-attributes-missing-with-semi-bfore-closing.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// expected-error at +2 {{expected ']'}}
+// expected-error at +1 {{expected external declaration}}
+[[fallthrough;]]
More information about the cfe-commits
mailing list