@@ -514,42 +514,21 @@ void LookupResult::resolveKind() {
514
514
const NamedDecl *HasNonFunction = nullptr ;
515
515
516
516
llvm::SmallVector<const NamedDecl *, 4 > EquivalentNonFunctions;
517
- llvm::BitVector RemovedDecls (N);
518
517
519
- for (unsigned I = 0 ; I < N; I++) {
518
+ unsigned UniqueTagIndex = 0 ;
519
+
520
+ unsigned I = 0 ;
521
+ while (I < N) {
520
522
const NamedDecl *D = Decls[I]->getUnderlyingDecl ();
521
523
D = cast<NamedDecl>(D->getCanonicalDecl ());
522
524
523
525
// Ignore an invalid declaration unless it's the only one left.
524
526
// 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];
528
529
continue ;
529
530
}
530
531
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
-
553
532
std::optional<unsigned > ExistingI;
554
533
555
534
// Redeclarations of types via typedef can occur both within a scope
@@ -582,7 +561,7 @@ void LookupResult::resolveKind() {
582
561
if (isPreferredLookupResult (getSema (), getLookupKind (), Decls[I],
583
562
Decls[*ExistingI]))
584
563
Decls[*ExistingI] = Decls[I];
585
- RemovedDecls. set (I) ;
564
+ Decls[I] = Decls[--N] ;
586
565
continue ;
587
566
}
588
567
@@ -593,6 +572,7 @@ void LookupResult::resolveKind() {
593
572
} else if (isa<TagDecl>(D)) {
594
573
if (HasTag)
595
574
Ambiguous = true ;
575
+ UniqueTagIndex = I;
596
576
HasTag = true ;
597
577
} else if (isa<FunctionTemplateDecl>(D)) {
598
578
HasFunction = true ;
@@ -608,7 +588,7 @@ void LookupResult::resolveKind() {
608
588
if (getSema ().isEquivalentInternalLinkageDeclaration (HasNonFunction,
609
589
D)) {
610
590
EquivalentNonFunctions.push_back (D);
611
- RemovedDecls. set (I) ;
591
+ Decls[I] = Decls[--N] ;
612
592
continue ;
613
593
}
614
594
if (D->isPlaceholderVar (getSema ().getLangOpts ()) &&
@@ -620,6 +600,28 @@ void LookupResult::resolveKind() {
620
600
}
621
601
HasNonFunction = D;
622
602
}
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 ;
623
625
}
624
626
625
627
// FIXME: This diagnostic should really be delayed until we're done with
@@ -628,15 +630,9 @@ void LookupResult::resolveKind() {
628
630
getSema ().diagnoseEquivalentInternalLinkageDeclarations (
629
631
getNameLoc (), HasNonFunction, EquivalentNonFunctions);
630
632
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];
636
633
Decls.truncate (N);
637
634
638
- if ((HasNonFunction && (HasFunction || HasUnresolved)) ||
639
- (HideTags && HasTag && (HasFunction || HasNonFunction || HasUnresolved)))
635
+ if (HasNonFunction && (HasFunction || HasUnresolved))
640
636
Ambiguous = true ;
641
637
642
638
if (Ambiguous && ReferenceToPlaceHolderVariable)
0 commit comments