mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-25 06:18:56 -04:00

Previously if a file-level function was defined inside befriending template class, it always was treated as defined. For instance, the code like: ``` int func(int x); template<typename T> class C1 { friend int func(int x) { return x; } }; template<typename T> class C2 { friend int func(int x) { return x; } }; ``` could not be compiled due to function redefinition, although not of the templates is instantiated. Moreover, the body of friend function can contain use of template parameters, attempt to get definition of such function outside any instantiation causes compiler abnormal termination. Other compilers (gcc, icc) follow viewpoint that the body of the function defined in friend declaration becomes available when corresponding class is instantiated. This patch implements this viewpoint in clang. Definitions introduced by friend declarations in template classes are not added to the redeclaration chain of corresponding function. Only when the template is instantiated, instantiation of the function definition is placed to the chain. The fix was made in collaboration with Richard Smith. This change fixes PR8035, PR17923, PR22307 and PR25848. Differential Revision: http://reviews.llvm.org/D16989 llvm-svn: 283207
20 lines
518 B
C++
20 lines
518 B
C++
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
|
|
|
namespace redecl_in_templ {
|
|
template<typename T> void redecl_in_templ() {
|
|
extern void func_1(); // expected-note {{previous declaration is here}}
|
|
extern int func_1(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
|
|
}
|
|
|
|
void g();
|
|
constexpr void (*p)() = g;
|
|
|
|
template<bool> struct X {};
|
|
template<> struct X<true> { typedef int type; };
|
|
|
|
template<typename T> void f() {
|
|
extern void g();
|
|
X<&g == p>::type n;
|
|
}
|
|
}
|