Skip to content

Commit 7d259b3

Browse files
committed
Revert "[Sema] Fix handling of functions that hide classes"
This reverts commit d031ff3. See https://reviews.llvm.org/D154503#4576393 for a reproducer and details.
1 parent 3dd5833 commit 7d259b3

File tree

2 files changed

+32
-409
lines changed

2 files changed

+32
-409
lines changed

clang/lib/Sema/SemaLookup.cpp

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -514,42 +514,21 @@ void LookupResult::resolveKind() {
514514
const NamedDecl *HasNonFunction = nullptr;
515515

516516
llvm::SmallVector<const NamedDecl *, 4> EquivalentNonFunctions;
517-
llvm::BitVector RemovedDecls(N);
518517

519-
for (unsigned I = 0; I < N; I++) {
518+
unsigned UniqueTagIndex = 0;
519+
520+
unsigned I = 0;
521+
while (I < N) {
520522
const NamedDecl *D = Decls[I]->getUnderlyingDecl();
521523
D = cast<NamedDecl>(D->getCanonicalDecl());
522524

523525
// Ignore an invalid declaration unless it's the only one left.
524526
// Also ignore HLSLBufferDecl which not have name conflict with other Decls.
525-
if ((D->isInvalidDecl() || isa<HLSLBufferDecl>(D)) &&
526-
N - RemovedDecls.count() > 1) {
527-
RemovedDecls.set(I);
527+
if ((D->isInvalidDecl() || isa<HLSLBufferDecl>(D)) && !(I == 0 && N == 1)) {
528+
Decls[I] = Decls[--N];
528529
continue;
529530
}
530531

531-
// C++ [basic.scope.hiding]p2:
532-
// A class name or enumeration name can be hidden by the name of
533-
// an object, function, or enumerator declared in the same
534-
// scope. If a class or enumeration name and an object, function,
535-
// or enumerator are declared in the same scope (in any order)
536-
// with the same name, the class or enumeration name is hidden
537-
// wherever the object, function, or enumerator name is visible.
538-
if (HideTags && isa<TagDecl>(D)) {
539-
bool Hidden = false;
540-
for (auto *OtherDecl : Decls) {
541-
if (canHideTag(OtherDecl) &&
542-
getContextForScopeMatching(OtherDecl)->Equals(
543-
getContextForScopeMatching(Decls[I]))) {
544-
RemovedDecls.set(I);
545-
Hidden = true;
546-
break;
547-
}
548-
}
549-
if (Hidden)
550-
continue;
551-
}
552-
553532
std::optional<unsigned> ExistingI;
554533

555534
// Redeclarations of types via typedef can occur both within a scope
@@ -582,7 +561,7 @@ void LookupResult::resolveKind() {
582561
if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
583562
Decls[*ExistingI]))
584563
Decls[*ExistingI] = Decls[I];
585-
RemovedDecls.set(I);
564+
Decls[I] = Decls[--N];
586565
continue;
587566
}
588567

@@ -593,6 +572,7 @@ void LookupResult::resolveKind() {
593572
} else if (isa<TagDecl>(D)) {
594573
if (HasTag)
595574
Ambiguous = true;
575+
UniqueTagIndex = I;
596576
HasTag = true;
597577
} else if (isa<FunctionTemplateDecl>(D)) {
598578
HasFunction = true;
@@ -608,7 +588,7 @@ void LookupResult::resolveKind() {
608588
if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
609589
D)) {
610590
EquivalentNonFunctions.push_back(D);
611-
RemovedDecls.set(I);
591+
Decls[I] = Decls[--N];
612592
continue;
613593
}
614594
if (D->isPlaceholderVar(getSema().getLangOpts()) &&
@@ -620,6 +600,28 @@ void LookupResult::resolveKind() {
620600
}
621601
HasNonFunction = D;
622602
}
603+
I++;
604+
}
605+
606+
// C++ [basic.scope.hiding]p2:
607+
// A class name or enumeration name can be hidden by the name of
608+
// an object, function, or enumerator declared in the same
609+
// scope. If a class or enumeration name and an object, function,
610+
// or enumerator are declared in the same scope (in any order)
611+
// with the same name, the class or enumeration name is hidden
612+
// wherever the object, function, or enumerator name is visible.
613+
// But it's still an error if there are distinct tag types found,
614+
// even if they're not visible. (ref?)
615+
if (N > 1 && HideTags && HasTag && !Ambiguous &&
616+
(HasFunction || HasNonFunction || HasUnresolved)) {
617+
const NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1];
618+
if (isa<TagDecl>(Decls[UniqueTagIndex]->getUnderlyingDecl()) &&
619+
getContextForScopeMatching(Decls[UniqueTagIndex])->Equals(
620+
getContextForScopeMatching(OtherDecl)) &&
621+
canHideTag(OtherDecl))
622+
Decls[UniqueTagIndex] = Decls[--N];
623+
else
624+
Ambiguous = true;
623625
}
624626

625627
// FIXME: This diagnostic should really be delayed until we're done with
@@ -628,15 +630,9 @@ void LookupResult::resolveKind() {
628630
getSema().diagnoseEquivalentInternalLinkageDeclarations(
629631
getNameLoc(), HasNonFunction, EquivalentNonFunctions);
630632

631-
// Remove decls by replacing them with decls from the end (which
632-
// means that we need to iterate from the end) and then truncating
633-
// to the new size.
634-
for (int I = RemovedDecls.find_last(); I >= 0; I = RemovedDecls.find_prev(I))
635-
Decls[I] = Decls[--N];
636633
Decls.truncate(N);
637634

638-
if ((HasNonFunction && (HasFunction || HasUnresolved)) ||
639-
(HideTags && HasTag && (HasFunction || HasNonFunction || HasUnresolved)))
635+
if (HasNonFunction && (HasFunction || HasUnresolved))
640636
Ambiguous = true;
641637

642638
if (Ambiguous && ReferenceToPlaceHolderVariable)

0 commit comments

Comments
 (0)