[PATCH] D19336: Repair redeclaration chain of friend template functions.
Serge Pavlov via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 20 11:28:10 PDT 2016
sepavloff created this revision.
sepavloff added a reviewer: rsmith.
sepavloff added a subscriber: cfe-commits.
When friend template function is parsed, it obtains wrong type. For
instance, in the code:
template<typename T1> void func(T1 *x);
template<typename T> struct C1 {
template<typename T1> void func(T1 *x);
};
the friend function func gets canonical type 'void (template-param-1-0)',
while type of the same function declared at file level is
'void (template-param-0-0)'. As a result, these two declarations are not
connected into redeclaration chain.
It occurs because beginning of template friend is parsed in the same way
as a declaration of member template. So template parameters get canonical
types as for a member template. Whether the declaration is a friend or
not can be determined only after declspec is parsed. It is too late, and
use of token look ahead is impractical to determine how parameters should
be handled. Type parameters should be fixed after friend declaration is
seen. They require shift of template parameter depth downward. It the
example above the shift would convert the type 'void (template-param-1-0)'
into 'void (template-param-0-0)'. However this change cannot be made for
all instances of template parameter, because friend function body may use
befriending class parameters as well, after the shift they would have the
same canonical representation as the friend function template parameters.
The fix implements update of canonical representation of friend template
function type. It allows to build up redeclaration chain correctly and
still does not break body of the friend function.
http://reviews.llvm.org/D19336
Files:
include/clang/Sema/Sema.h
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaTemplate.cpp
test/SemaTemplate/friend-template-redecl.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19336.54396.patch
Type: text/x-patch
Size: 11861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160420/e77ca2f3/attachment-0001.bin>
More information about the cfe-commits
mailing list