return getLinkage() == ExternalLinkage;
}
- /// \brief True if this decl has external linkage. Don't cache the linkage,
- /// because we are not finished setting up the redecl chain for the decl.
- bool hasExternalLinkageUncached() const;
-
/// \brief Determines the visibility of this entity.
Visibility getVisibility() const {
return getLinkageAndVisibility().getVisibility();
static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD);
+ static bool
+ shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, const NamedDecl *New) {
+ // We are about to link these. It is now safe to compute the linkage of
+ // the new decl. If the new decl has external linkage, we will
+ // link it with the hidden decl (which also has external linkage) and
+ // it will keep having external linkage. If it has internal linkage, we
+ // will not link it. Since it has no previous decls, it will remain
+ // with internal linkage.
+ return !Old->isHidden() || New->hasExternalLinkage();
+ }
+
public:
typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy;
typedef OpaquePtr<TemplateName> TemplateTy;
if (!old->isHidden())
continue;
- // If either has no-external linkage, ignore the old declaration.
- // If this declaration would have external linkage if it were the first
- // declaration of this name, then it may in fact be a redeclaration of
- // some hidden declaration, so include those too. We don't need to worry
- // about some previous visible declaration giving this declaration external
- // linkage, because in that case, we'll mark this declaration as a redecl
- // of the visible decl, and that decl will already be a redecl of the
- // hidden declaration if that's appropriate.
- //
- // Don't cache this linkage computation, because it's not yet correct: we
- // may later give this declaration a previous declaration which changes
- // its linkage.
- if (old->getLinkage() != ExternalLinkage ||
- !decl->hasExternalLinkageUncached())
+ if (old->getLinkage() != ExternalLinkage)
filter.erase();
}
return New->setInvalidDecl();
}
+ if (!shouldLinkPossiblyHiddenDecl(Old, New))
+ return;
+
// C++ [class.mem]p1:
// A member shall not be declared twice in the member-specification [...]
//
// there's no more work to do here; we'll just add the new
// function to the scope.
if (!AllowOverloadingOfFunction(Previous, Context)) {
- Redeclaration = true;
- OldDecl = Previous.getFoundDecl();
+ NamedDecl *Candidate = Previous.getFoundDecl();
+ if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) {
+ Redeclaration = true;
+ OldDecl = Candidate;
+ }
} else {
switch (CheckOverload(S, NewFD, Previous, OldDecl,
/*NewIsUsingDecl*/ false)) {