[PATCH] D157838: [clang-repl] Disambiguate declarations with private typedefs
Jonas Hahnfeld via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 02:30:41 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c274ba4108b: [clang-repl] Disambiguate declarations with private typedefs (authored by Hahnfeld).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157838/new/
https://reviews.llvm.org/D157838
Files:
clang/lib/Parse/ParseTentative.cpp
clang/test/Interpreter/disambiguate-decl-stmt.cpp
Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===================================================================
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -1,8 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify -fincremental-extensions -std=c++20 %s
// RUN: %clang_cc1 -fsyntax-only -DMS -fms-extensions -verify -fincremental-extensions -std=c++20 %s
-// expected-no-diagnostics
-
extern "C" int printf(const char*,...);
// Decls which are hard to disambiguate
@@ -47,6 +45,37 @@
// Ctors
+// Private typedefs / using declarations
+class PrivateUsingMember { using T = int; T f(); };
+PrivateUsingMember::T PrivateUsingMember::f() { return 0; }
+
+class PrivateUsingVar { using T = int; static T i; };
+PrivateUsingVar::T PrivateUsingVar::i = 42;
+
+// The same with namespaces
+namespace PrivateUsingNamespace { class Member { using T = int; T f(); }; }
+PrivateUsingNamespace::Member::T PrivateUsingNamespace::Member::f() { return 0; }
+
+namespace PrivateUsingNamespace { class Var { using T = int; static T i; }; }
+PrivateUsingNamespace::Var::T PrivateUsingNamespace::Var::i = 42;
+
+// The same with friend declarations
+class PrivateUsingFriendMember;
+class PrivateUsingFriendVar;
+class PrivateUsingFriend { friend class PrivateUsingFriendMember; friend class PrivateUsingFriendVar; using T = int; };
+class PrivateUsingFriendMember { PrivateUsingFriend::T f(); };
+PrivateUsingFriend::T PrivateUsingFriendMember::f() { return 0; }
+
+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 at -1 2 {{implicitly declared private here}}
+PR13642::Inner::i = 5;
+// expected-error at -1 2 {{'Inner' is a private member of 'PR13642'}}
+
// Deduction guide
template<typename T> struct A { A(); A(T); };
A() -> A<int>;
Index: clang/lib/Parse/ParseTentative.cpp
===================================================================
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -83,6 +83,17 @@
isDeductionGuide,
DeclSpec::FriendSpecified::No))
return true;
+ } else if (SS.isNotEmpty()) {
+ // If the scope is not empty, it could alternatively be something like
+ // a typedef or using declaration. That declaration might be private
+ // in the global context, which would be diagnosed by calling into
+ // isCXXSimpleDeclaration, but may actually be fine in the context of
+ // member functions and static variable definitions. Check if the next
+ // token is also an identifier and assume a declaration.
+ // We cannot check if the scopes match because the declarations could
+ // involve namespaces and friend declarations.
+ if (NextToken().is(tok::identifier))
+ return true;
}
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157838.552637.patch
Type: text/x-patch
Size: 3178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230823/07311338/attachment-0001.bin>
More information about the cfe-commits
mailing list