diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 12 | ||||
| -rw-r--r-- | clang/test/Modules/Inputs/PR24954/A.h | 10 | ||||
| -rw-r--r-- | clang/test/Modules/Inputs/PR24954/B.h | 30 | ||||
| -rw-r--r-- | clang/test/Modules/Inputs/PR24954/module.modulemap | 9 | ||||
| -rw-r--r-- | clang/test/Modules/pr24954.cpp | 7 |
5 files changed, 66 insertions, 2 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index ee475d3cc52..3e04bc5ad7d 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -5751,8 +5751,16 @@ static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { } void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { - // TU and namespaces are handled elsewhere. - if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC)) + // TU is handled elsewhere. + if (isa<TranslationUnitDecl>(DC)) + return; + + // Namespaces are handled elsewhere, except for template instantiations of + // FunctionTemplateDecls in namespaces. We are interested in cases where the + // local instantiations are added to an imported context. Only happens when + // adding ADL lookup candidates, for example templated friends. + if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && + !isa<FunctionTemplateDecl>(D)) return; // We're only interested in cases where a local declaration is added to an diff --git a/clang/test/Modules/Inputs/PR24954/A.h b/clang/test/Modules/Inputs/PR24954/A.h new file mode 100644 index 00000000000..5e5d5bf92ce --- /dev/null +++ b/clang/test/Modules/Inputs/PR24954/A.h @@ -0,0 +1,10 @@ +#include "B.h" + +template <class T> +class Expr { +public: + void print(B::basic_ostream<char>& os) { + os << B::setw(42); + os << B::endl; + } +}; diff --git a/clang/test/Modules/Inputs/PR24954/B.h b/clang/test/Modules/Inputs/PR24954/B.h new file mode 100644 index 00000000000..a8ddc718927 --- /dev/null +++ b/clang/test/Modules/Inputs/PR24954/B.h @@ -0,0 +1,30 @@ +namespace B { + + template <class _CharT> + struct basic_ostream { + basic_ostream& operator<<(basic_ostream& (*__pf)()); + }; + + + template <class _CharT> basic_ostream<_CharT>& + endl(); + + struct S1 { + template <class _CharT> friend void + operator<<(basic_ostream<_CharT>& __os, const S1& __x); + }; + + S1 setw(int __n); + + template <class _CharT> class S2; + + template <class _CharT> void + operator<<(basic_ostream<_CharT>& __os, const S2<_CharT>& __x); + + template <class _CharT> + struct S2 { + template <class _Cp> friend void + operator<<(basic_ostream<_Cp>& __os, const S2<_Cp>& __x); + }; + +} diff --git a/clang/test/Modules/Inputs/PR24954/module.modulemap b/clang/test/Modules/Inputs/PR24954/module.modulemap new file mode 100644 index 00000000000..49374181d75 --- /dev/null +++ b/clang/test/Modules/Inputs/PR24954/module.modulemap @@ -0,0 +1,9 @@ +module A { + header "A.h" + export * +} + +module B { + header "B.h" + export * +} diff --git a/clang/test/Modules/pr24954.cpp b/clang/test/Modules/pr24954.cpp new file mode 100644 index 00000000000..407ee06e402 --- /dev/null +++ b/clang/test/Modules/pr24954.cpp @@ -0,0 +1,7 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -I%S/Inputs/PR24954 -verify %s +// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I%S/Inputs/PR24954 -verify %s + +#include "A.h" + +// expected-no-diagnostics |

