Skip to content

Commit 38908de

Browse files
kadircettru
authored andcommitted
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. (cherry picked from commit 7d259b3)
1 parent 4985bd4 commit 38908de

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
@@ -513,42 +513,21 @@ void LookupResult::resolveKind() {
513513
const NamedDecl *HasNonFunction = nullptr;
514514

515515
llvm::SmallVector<const NamedDecl *, 4> EquivalentNonFunctions;
516-
llvm::BitVector RemovedDecls(N);
517516

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

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

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

554533
// Redeclarations of types via typedef can occur both within a scope
@@ -581,7 +560,7 @@ void LookupResult::resolveKind() {
581560
if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
582561
Decls[*ExistingI]))
583562
Decls[*ExistingI] = Decls[I];
584-
RemovedDecls.set(I);
563+
Decls[I] = Decls[--N];
585564
continue;
586565
}
587566

@@ -592,6 +571,7 @@ void LookupResult::resolveKind() {
592571
} else if (isa<TagDecl>(D)) {
593572
if (HasTag)
594573
Ambiguous = true;
574+
UniqueTagIndex = I;
595575
HasTag = true;
596576
} else if (isa<FunctionTemplateDecl>(D)) {
597577
HasFunction = true;
@@ -607,14 +587,36 @@ void LookupResult::resolveKind() {
607587
if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
608588
D)) {
609589
EquivalentNonFunctions.push_back(D);
610-
RemovedDecls.set(I);
590+
Decls[I] = Decls[--N];
611591
continue;
612592
}
613593

614594
Ambiguous = true;
615595
}
616596
HasNonFunction = D;
617597
}
598+
I++;
599+
}
600+
601+
// C++ [basic.scope.hiding]p2:
602+
// A class name or enumeration name can be hidden by the name of
603+
// an object, function, or enumerator declared in the same
604+
// scope. If a class or enumeration name and an object, function,
605+
// or enumerator are declared in the same scope (in any order)
606+
// with the same name, the class or enumeration name is hidden
607+
// wherever the object, function, or enumerator name is visible.
608+
// But it's still an error if there are distinct tag types found,
609+
// even if they're not visible. (ref?)
610+
if (N > 1 && HideTags && HasTag && !Ambiguous &&
611+
(HasFunction || HasNonFunction || HasUnresolved)) {
612+
const NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1];
613+
if (isa<TagDecl>(Decls[UniqueTagIndex]->getUnderlyingDecl()) &&
614+
getContextForScopeMatching(Decls[UniqueTagIndex])->Equals(
615+
getContextForScopeMatching(OtherDecl)) &&
616+
canHideTag(OtherDecl))
617+
Decls[UniqueTagIndex] = Decls[--N];
618+
else
619+
Ambiguous = true;
618620
}
619621

620622
// FIXME: This diagnostic should really be delayed until we're done with
@@ -623,15 +625,9 @@ void LookupResult::resolveKind() {
623625
getSema().diagnoseEquivalentInternalLinkageDeclarations(
624626
getNameLoc(), HasNonFunction, EquivalentNonFunctions);
625627

626-
// Remove decls by replacing them with decls from the end (which
627-
// means that we need to iterate from the end) and then truncating
628-
// to the new size.
629-
for (int I = RemovedDecls.find_last(); I >= 0; I = RemovedDecls.find_prev(I))
630-
Decls[I] = Decls[--N];
631628
Decls.truncate(N);
632629

633-
if ((HasNonFunction && (HasFunction || HasUnresolved)) ||
634-
(HideTags && HasTag && (HasFunction || HasNonFunction || HasUnresolved)))
630+
if (HasNonFunction && (HasFunction || HasUnresolved))
635631
Ambiguous = true;
636632

637633
if (Ambiguous)

0 commit comments

Comments
 (0)