diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2018-10-10 17:17:51 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2018-10-10 17:17:51 +0000 |
commit | c72f348e95ced873b69abde93040060a12a1a3a6 (patch) | |
tree | 03ae4eb8fe0bde3870e44cad2c4bd35a270cc965 /test/SemaCXX/friend-template-redecl.cpp | |
parent | 27fe8790f1e12d29a15188192f52f2ac3e4fd672 (diff) | |
download | clang-c72f348e95ced873b69abde93040060a12a1a3a6.tar.gz |
[Sema] Fix a multiple definition bug with friends and templates
The problem was that MergeFunctionDecl sometimes needs the injected template
arguments of a FunctionTemplateDecl, but is called before adding the new
template to the redecl chain. This leads to multiple common pointers in the same
redecl chain, each with their own identical instantiation. Fix this by merging
the the common state before inserting the new template into the redecl chain.
rdar://44810129
Differential revision: https://reviews.llvm.org/D53046
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344157 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/friend-template-redecl.cpp')
-rw-r--r-- | test/SemaCXX/friend-template-redecl.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/SemaCXX/friend-template-redecl.cpp b/test/SemaCXX/friend-template-redecl.cpp new file mode 100644 index 0000000000..3e05964fb2 --- /dev/null +++ b/test/SemaCXX/friend-template-redecl.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -std=c++17 -verify -emit-llvm-only %s + +// expected-no-diagnostics + +template <class T> void bar(const T &t) { foo(t); } + +template <class> +struct HasFriend { + template <class T> + friend void foo(const HasFriend<T> &m) noexcept(false); +}; + +template <class T> +void foo(const HasFriend<T> &m) noexcept(false) {} + +void f() { + HasFriend<int> x; + foo(x); + bar(x); +} |