[modules] When determining whether a name from a module replaces a name we
already have, check whether the name from the module is actually newer than the
existing declaration. If it isn't, we might (say) replace a visible declaration
with an injected friend, and thus make it invisible (or lose a default argument
or an array bound).
llvm-svn: 228661
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 84ed286..ee2f760 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -179,14 +179,17 @@
const PrintingPolicy &Policy,
bool Qualified) const;
- /// declarationReplaces - Determine whether this declaration, if
+ /// \brief Determine whether this declaration, if
/// known to be well-formed within its context, will replace the
/// declaration OldD if introduced into scope. A declaration will
/// replace another declaration if, for example, it is a
/// redeclaration of the same variable or function, but not if it is
/// a declaration of a different kind (function vs. class) or an
/// overloaded function.
- bool declarationReplaces(NamedDecl *OldD) const;
+ ///
+ /// \param IsKnownNewer \c true if this declaration is known to be newer
+ /// than \p OldD (for instance, if this declaration is newly-created).
+ bool declarationReplaces(NamedDecl *OldD, bool IsKnownNewer = true) const;
/// \brief Determine whether this declaration has linkage.
bool hasLinkage() const;
diff --git a/clang/include/clang/AST/DeclContextInternals.h b/clang/include/clang/AST/DeclContextInternals.h
index 9068c00..e0830d0 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -163,10 +163,10 @@
/// HandleRedeclaration - If this is a redeclaration of an existing decl,
/// replace the old one with D and return true. Otherwise return false.
- bool HandleRedeclaration(NamedDecl *D) {
+ bool HandleRedeclaration(NamedDecl *D, bool IsKnownNewer) {
// Most decls only have one entry in their list, special case it.
if (NamedDecl *OldD = getAsDecl()) {
- if (!D->declarationReplaces(OldD))
+ if (!D->declarationReplaces(OldD, IsKnownNewer))
return false;
setOnlyValue(D);
return true;
@@ -177,7 +177,7 @@
for (DeclsTy::iterator OD = Vec.begin(), ODEnd = Vec.end();
OD != ODEnd; ++OD) {
NamedDecl *OldD = *OD;
- if (D->declarationReplaces(OldD)) {
+ if (D->declarationReplaces(OldD, IsKnownNewer)) {
*OD = D;
return true;
}