Skip to content

Commit 57fd785

Browse files
committed
Revert "[Clang][Sema] access checking of friend declaration should not be delayed (llvm#91430)"
This reverts commit 200f3bd.
1 parent a6ca703 commit 57fd785

File tree

5 files changed

+7
-67
lines changed

5 files changed

+7
-67
lines changed

clang/include/clang/Sema/Scope.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ class Scope {
160160

161161
/// This is a scope of type alias declaration.
162162
TypeAliasScope = 0x20000000,
163-
164-
/// This is a scope of friend declaration.
165-
FriendScope = 0x40000000,
166163
};
167164

168165
private:
@@ -590,9 +587,6 @@ class Scope {
590587
/// Determine whether this scope is a type alias scope.
591588
bool isTypeAliasScope() const { return getFlags() & Scope::TypeAliasScope; }
592589

593-
/// Determine whether this scope is a friend scope.
594-
bool isFriendScope() const { return getFlags() & Scope::FriendScope; }
595-
596590
/// Returns if rhs has a higher scope depth than this.
597591
///
598592
/// The caller is responsible for calling this only if one of the two scopes

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,12 +4219,9 @@ void Parser::ParseDeclarationSpecifiers(
42194219

42204220
// friend
42214221
case tok::kw_friend:
4222-
if (DSContext == DeclSpecContext::DSC_class) {
4222+
if (DSContext == DeclSpecContext::DSC_class)
42234223
isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID);
4224-
Scope *CurS = getCurScope();
4225-
if (!isInvalid && CurS)
4226-
CurS->setFlags(CurS->getFlags() | Scope::FriendScope);
4227-
} else {
4224+
else {
42284225
PrevSpec = ""; // not actually used by the diagnostic
42294226
DiagID = diag::err_friend_invalid_in_context;
42304227
isInvalid = true;

clang/lib/Sema/Scope.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ void Scope::dumpImpl(raw_ostream &OS) const {
233233
{LambdaScope, "LambdaScope"},
234234
{OpenACCComputeConstructScope, "OpenACCComputeConstructScope"},
235235
{TypeAliasScope, "TypeAliasScope"},
236-
{FriendScope, "FriendScope"},
237236
};
238237

239238
for (auto Info : FlagInfo) {

clang/lib/Sema/SemaAccess.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,32 +1469,12 @@ static Sema::AccessResult CheckAccess(Sema &S, SourceLocation Loc,
14691469
// specifier, like this:
14701470
// A::private_type A::foo() { ... }
14711471
//
1472-
// friend declaration should not be delayed because it may lead to incorrect
1473-
// redeclaration chain, such as:
1474-
// class D {
1475-
// class E{
1476-
// class F{};
1477-
// friend void foo(D::E::F& q);
1478-
// };
1479-
// friend void foo(D::E::F& q);
1480-
// };
1472+
// Or we might be parsing something that will turn out to be a friend:
1473+
// void foo(A::private_type);
1474+
// void B::foo(A::private_type);
14811475
if (S.DelayedDiagnostics.shouldDelayDiagnostics()) {
1482-
// [class.friend]p9:
1483-
// A member nominated by a friend declaration shall be accessible in the
1484-
// class containing the friend declaration. The meaning of the friend
1485-
// declaration is the same whether the friend declaration appears in the
1486-
// private, protected, or public ([class.mem]) portion of the class
1487-
// member-specification.
1488-
Scope *TS = S.getCurScope();
1489-
bool IsFriendDeclaration = false;
1490-
while (TS && !IsFriendDeclaration) {
1491-
IsFriendDeclaration = TS->isFriendScope();
1492-
TS = TS->getParent();
1493-
}
1494-
if (!IsFriendDeclaration) {
1495-
S.DelayedDiagnostics.add(DelayedDiagnostic::makeAccess(Loc, Entity));
1496-
return Sema::AR_delayed;
1497-
}
1476+
S.DelayedDiagnostics.add(DelayedDiagnostic::makeAccess(Loc, Entity));
1477+
return Sema::AR_delayed;
14981478
}
14991479

15001480
EffectiveContext EC(S.CurContext);

clang/test/SemaCXX/PR12361.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)