https://github.com/fogsong233 updated https://github.com/llvm/llvm-project/pull/178842
>From d79e92e4b955be1f134a91ea47761043ddf85aab Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Fri, 30 Jan 2026 14:37:57 +0800 Subject: [PATCH 1/6] fix. --- clang/lib/Parse/ParseTentative.cpp | 13 ++++++++++++- clang/test/Interpreter/disambiguate-decl-stmt.cpp | 5 ++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 9622a00687ca5..2a24256929ea9 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Parse/Parser.h" +#include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/ParsedTemplate.h" using namespace clang; @@ -78,7 +79,17 @@ bool Parser::isCXXDeclarationStatement( [[fallthrough]]; // simple-declaration default: - return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); + // Ignore access restrictions during tentative parsing. A private type used + // as a return value would otherwise trigger a lookup error. We only need + // to identify if the sequence represents a type; the actual access rights + // will be verified during formal parsing when the member function's + // context is fully known. + if (DisambiguatingWithExpression) { + SuppressAccessChecks AccessExporter(*this, true); + return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); + } else { + return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); + } } } diff --git a/clang/test/Interpreter/disambiguate-decl-stmt.cpp b/clang/test/Interpreter/disambiguate-decl-stmt.cpp index 1f4d5e267288b..24902cee8ed1f 100644 --- a/clang/test/Interpreter/disambiguate-decl-stmt.cpp +++ b/clang/test/Interpreter/disambiguate-decl-stmt.cpp @@ -70,11 +70,10 @@ class PrivateUsingFriendVar { static PrivateUsingFriend::T i; }; PrivateUsingFriend::T PrivateUsingFriendVar::i = 42; // The following should still diagnose (inspired by PR13642) -// FIXME: Should not be diagnosed twice! class PR13642 { class Inner { public: static int i; }; }; -// expected-note@-1 2 {{implicitly declared private here}} +// expected-note@-1 {{implicitly declared private here}} PR13642::Inner::i = 5; -// expected-error@-1 2 {{'Inner' is a private member of 'PR13642'}} +// expected-error@-1 {{'Inner' is a private member of 'PR13642'}} // Deduction guide template<typename T> struct A { A(); A(T); }; >From 39ee8a8b56dcc1355e07cfa1268ea46ae7ee40b4 Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Sun, 8 Feb 2026 18:51:00 +0800 Subject: [PATCH 2/6] using revert --- clang/lib/Parse/ParseTentative.cpp | 18 ++++++++++++------ clang/test/Interpreter/access.cpp | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 clang/test/Interpreter/access.cpp diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 2a24256929ea9..985563d737a93 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -79,14 +79,20 @@ bool Parser::isCXXDeclarationStatement( [[fallthrough]]; // simple-declaration default: - // Ignore access restrictions during tentative parsing. A private type used - // as a return value would otherwise trigger a lookup error. We only need - // to identify if the sequence represents a type; the actual access rights - // will be verified during formal parsing when the member function's - // context is fully known. + if (DisambiguatingWithExpression) { + TentativeParsingAction TPA(*this, true); + // We will do not check access checks here, because we want to allow + // parsing of declarations. Access will be checked later. SuppressAccessChecks AccessExporter(*this, true); - return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); + if (isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false)) { + // Do not annotate the tokens, otherwise access will be neglected later. + TPA.Revert(); + return true; + } + TPA.Commit(); + return false; + } else { return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); } diff --git a/clang/test/Interpreter/access.cpp b/clang/test/Interpreter/access.cpp new file mode 100644 index 0000000000000..3b23c2947d319 --- /dev/null +++ b/clang/test/Interpreter/access.cpp @@ -0,0 +1,15 @@ +// REQUIRES: host-supports-jit +// RUN: cat %s | clang-repl 2>&1 | FileCheck %s + +struct A { }; + +class B { using u = A; const static int p = 1; public: u *foo(); }; + +B::u* foo() { return nullptr; } +// CHECK: error: 'u' is a private member of 'B' + +B::u * B::foo() { return nullptr; } +// CHECK-NOT: error: 'u' is a private member of 'B' + +int p = B::p; +// CHECK: error: 'p' is a private member of 'B' \ No newline at end of file >From 2dffdee5173635881c62f09b7e1fc74d931eb331 Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Mon, 9 Feb 2026 18:07:56 +0800 Subject: [PATCH 3/6] remove else return Co-authored-by: Vassil Vassilev <[email protected]> --- clang/lib/Parse/ParseTentative.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 985563d737a93..639b6f9b80663 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -93,8 +93,8 @@ bool Parser::isCXXDeclarationStatement( TPA.Commit(); return false; - } else { - return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); + } + return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); } } } >From d59cdad8084c865bd46255fecd0ce664cce02401 Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Mon, 9 Feb 2026 22:12:30 +0800 Subject: [PATCH 4/6] remove an extra brace --- clang/lib/Parse/ParseTentative.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index d34f3fb7e4e0f..0b677f13f3082 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -96,7 +96,6 @@ bool Parser::isCXXDeclarationStatement( } return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); } - } } bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) { >From 7b2ed4be00a5dc1bd7467924ebb3c029a9d33936 Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Mon, 9 Feb 2026 22:57:25 +0800 Subject: [PATCH 5/6] fix format --- clang/lib/Parse/ParseTentative.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 0b677f13f3082..f0bf4b1bbe6d0 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -92,7 +92,6 @@ bool Parser::isCXXDeclarationStatement( } TPA.Commit(); return false; - } return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); } >From 56d6ecd877913992ed5816e02a3e34f4ba1b0a99 Mon Sep 17 00:00:00 2001 From: fogsong233 <[email protected]> Date: Mon, 9 Feb 2026 22:57:48 +0800 Subject: [PATCH 6/6] fix format --- clang/lib/Parse/ParseTentative.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index f0bf4b1bbe6d0..b9edbaee078b2 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -94,7 +94,7 @@ bool Parser::isCXXDeclarationStatement( return false; } return isCXXSimpleDeclaration(/*AllowForRangeDecl=*/false); - } + } } bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
