[clang] [clang] Reject __super when preceded by a scope specifier (PR #221492)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 19:20:08 PDT 2026
https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/221492
>From 271c9e10a12e418b3f7f8882fef70e1571366171 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sat, 5 Sep 2026 16:50:25 -0400
Subject: [PATCH 1/5] [clang] Reject __super when preceded by a scope specifier
The `__super` keyword is an MSVC extension that refers to the base class of the current class context. It is fundamentally invalid for `__super` to be qualified by another scope specifier (e.g. `::__super` or `N::__super`).
Fixes #212988
---
clang/lib/Parse/ParseExprCXX.cpp | 2 +-
clang/test/Parser/recovery.cpp | 2 +-
clang/test/SemaCXX/MicrosoftSuper.cpp | 7 +++++++
3 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index ae741af7249cf..63f7938c6fc64 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -153,7 +153,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
}
}
- if (Tok.is(tok::kw___super)) {
+ if (!HasScopeSpecifier && Tok.is(tok::kw___super)) {
SourceLocation SuperLoc = ConsumeToken();
if (!Tok.is(tok::coloncolon)) {
Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp
index 0637d4cbe72ae..be0b847b9ceb7 100644
--- a/clang/test/Parser/recovery.cpp
+++ b/clang/test/Parser/recovery.cpp
@@ -210,7 +210,7 @@ namespace InvalidEmptyNames {
// These shouldn't crash, the diagnostics aren't important.
struct ::, struct ::; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
enum ::, enum ::; // expected-error 2 {{expected identifier}}
-struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
+struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}}
class :: : {} a; // expected-error {{expected identifier}} expected-error {{expected class name}}
diff --git a/clang/test/SemaCXX/MicrosoftSuper.cpp b/clang/test/SemaCXX/MicrosoftSuper.cpp
index d117b93523363..98f087708d72d 100644
--- a/clang/test/SemaCXX/MicrosoftSuper.cpp
+++ b/clang/test/SemaCXX/MicrosoftSuper.cpp
@@ -21,6 +21,13 @@ struct Base1 {
typedef int XXX;
};
+struct InvalidGlobalQualifier : Base1 {
+ // 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}}
+};
+
struct Derived : Base1 {
__super::XXX x;
typedef __super::XXX Type;
>From 0b4d1815baf8a619325a0fafd03268696632ce33 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sun, 6 Sep 2026 14:19:48 -0400
Subject: [PATCH 2/5] Update ReleaseNotes.md
---
clang/docs/ReleaseNotes.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 042d7112dbe7d..20815db55beab 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -531,6 +531,8 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where top-level CV qualifiers (such as ``const``) were dropped from pointers modified by Microsoft pointer attributes (like ``__ptr32`` and ``__ptr64``) and WebAssembly's ``__funcref``.
+- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to fail elsewhere.
+
- Fixed an issue where we tried to compare invalid NTTPs for variable declarations, which ended up in hitting an assertion with a constrained non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
- Fixed a crash when a using-declaration naming an unresolvable member of a
>From bffeb8118838c2009419c57720537cdfabf98eb5 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sun, 6 Sep 2026 20:30:02 -0400
Subject: [PATCH 3/5] Update clang/docs/ReleaseNotes.md
Co-authored-by: Shengxin Pei <TPPPP72 at outlook.com>
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 20815db55beab..29a960d7a7586 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -531,7 +531,7 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where top-level CV qualifiers (such as ``const``) were dropped from pointers modified by Microsoft pointer attributes (like ``__ptr32`` and ``__ptr64``) and WebAssembly's ``__funcref``.
-- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to fail elsewhere.
+- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to assertion fail elsewhere.
- Fixed an issue where we tried to compare invalid NTTPs for variable declarations, which ended up in hitting an assertion with a constrained non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
>From 34423c15bd0aefbde3b2f8f1e346e561033a3b67 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Mon, 7 Sep 2026 12:44:09 -0400
Subject: [PATCH 4/5] Update ReleaseNotes.md
Co-authored-by: Corentin Jabot <corentinjabot at gmail.com>
---
clang/docs/ReleaseNotes.md | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 29a960d7a7586..3a8b6d334ea9c 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -531,8 +531,7 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where top-level CV qualifiers (such as ``const``) were dropped from pointers modified by Microsoft pointer attributes (like ``__ptr32`` and ``__ptr64``) and WebAssembly's ``__funcref``.
-- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to assertion fail elsewhere.
-
+- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to assertion fail elsewhere. (#GH212988)
- Fixed an issue where we tried to compare invalid NTTPs for variable declarations, which ended up in hitting an assertion with a constrained non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
- Fixed a crash when a using-declaration naming an unresolvable member of a
>From 8f1d7c48eaf47830f4c8fd2e7da3d7a88978c455 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Mon, 7 Sep 2026 22:19:57 -0400
Subject: [PATCH 5/5] Fix formatting for __super in ReleaseNotes.md
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 3a8b6d334ea9c..6a6ab399a0f3f 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -531,7 +531,7 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where top-level CV qualifiers (such as ``const``) were dropped from pointers modified by Microsoft pointer attributes (like ``__ptr32`` and ``__ptr64``) and WebAssembly's ``__funcref``.
-- Fixed a bug where we accepted __super being qualified by a scope specifier, causing codegen to assertion fail elsewhere. (#GH212988)
+- Fixed a bug where we accepted ``__super`` being qualified by a scope specifier, causing codegen to assertion fail elsewhere. (#GH212988)
- Fixed an issue where we tried to compare invalid NTTPs for variable declarations, which ended up in hitting an assertion with a constrained non-plain-auto NTTP, which we don't quite implement yet. (#GH208658)
- Fixed a crash when a using-declaration naming an unresolvable member of a
More information about the cfe-commits
mailing list