[clang] [clang][Parser] Reject qualified __super specifiers (PR #214520)
Matthias Görgens via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 8 09:55:54 PDT 2026
https://github.com/matthiasgoergens updated https://github.com/llvm/llvm-project/pull/214520
>From 02485465bd5dddfffed530d60f69764ded47155a Mon Sep 17 00:00:00 2001
From: Matthias Goergens <matthias.goergens at gmail.com>
Date: Sun, 2 Aug 2026 23:49:14 +0800
Subject: [PATCH 1/2] [clang][Parser] Reject qualified __super specifiers
---
clang/lib/Parse/ParseExprCXX.cpp | 3 ++-
clang/test/SemaCXX/MicrosoftSuper.cpp | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 06ff45da413ca..97a9e49308258 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -153,7 +153,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
}
}
- if (Tok.is(tok::kw___super)) {
+ if (Tok.is(tok::kw___super) &&
+ (!HasScopeSpecifier || NextToken().isNot(tok::coloncolon))) {
SourceLocation SuperLoc = ConsumeToken();
if (!Tok.is(tok::coloncolon)) {
Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
diff --git a/clang/test/SemaCXX/MicrosoftSuper.cpp b/clang/test/SemaCXX/MicrosoftSuper.cpp
index d117b93523363..89445b512b409 100644
--- a/clang/test/SemaCXX/MicrosoftSuper.cpp
+++ b/clang/test/SemaCXX/MicrosoftSuper.cpp
@@ -156,3 +156,7 @@ struct A : B {
void f() { int a = this->__super::a; }
};
}
+
+struct InvalidGlobalQualifier : Base1 {
+ ::__super::; // expected-error {{expected unqualified-id}}
+};
>From 7a744d82ef95c1d9f77340f838d527abf28b444a Mon Sep 17 00:00:00 2001
From: Matthias Goergens <matthias.goergens at gmail.com>
Date: Thu, 6 Aug 2026 22:26:16 +0800
Subject: [PATCH 2/2] [clang][Parser] Strengthen qualified __super regression
test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
A bare '::__super::;' already yields 'expected unqualified-id' on an
unpatched release build, so the previous test only pinned the bug via
the assertion abort in asserts builds. Use '::__super::XXX x;' — the
original issue reproducer — which an unpatched release build silently
accepts, so the test now discriminates in both release and asserts
builds.
---
clang/test/SemaCXX/MicrosoftSuper.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/clang/test/SemaCXX/MicrosoftSuper.cpp b/clang/test/SemaCXX/MicrosoftSuper.cpp
index 89445b512b409..cae271449dd29 100644
--- a/clang/test/SemaCXX/MicrosoftSuper.cpp
+++ b/clang/test/SemaCXX/MicrosoftSuper.cpp
@@ -158,5 +158,8 @@ struct A : B {
}
struct InvalidGlobalQualifier : Base1 {
- ::__super::; // expected-error {{expected unqualified-id}}
+ // A parser that drops the global qualifier is left with the valid
+ // declaration `__super::XXX x;` and accepts this line silently; expecting
+ // a diagnostic here catches that even in builds without assertions.
+ ::__super::XXX x; // expected-error {{expected unqualified-id}}
};
More information about the cfe-commits
mailing list