https://github.com/AZero13 created https://github.com/llvm/llvm-project/pull/221492
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 >From b1e6f441212f8f430c525c879f4c84751a51100b Mon Sep 17 00:00:00 2001 From: AZero13 <[email protected]> Date: Sat, 5 Sep 2026 16:50:25 -0400 Subject: [PATCH] [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/SemaCXX/MicrosoftSuper.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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/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; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
