<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Lost visibility attr on template friend class"
href="https://bugs.llvm.org/show_bug.cgi?id=36621">36621</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Lost visibility attr on template friend class
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>stephan.bergmann.secondary@googlemail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>At least with recent trunk,
<span class="quote">> $ cat test.cc
> namespace std { class type_info {}; }
> namespace N {
> template<typename> struct S1 {
> template<typename>
> friend struct __attribute__ ((__type_visibility__("default"))) S2;
> };
> template<typename>
> struct __attribute__ ((__type_visibility__("default"))) S2 {
> S1<void> f();
> };
> }
> void f(N::S2<bool> s) {
> s.f(); // #1
> typeid(N::S2<void>);
> }</span >
>
<span class="quote">> $ clang++ -Wno-everything -fvisibility=hidden -c test.cc -S -emit-llvm -o - | grep @_ZTIN1N2S2IvEE
> @_ZTIN1N2S2IvEE = linkonce_odr hidden constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTSN1N2S2IvEE, i32 0, i32 0) }</span >
the type info for N::S2<void> is emitted with hidden visibility, although S2
has default visibility. If you comment out the line marked #1, it is correctly
emitted with default visibility (the token "hidden" disappears from the grepped
line).
What happens during the call to LinkageComputer::getDeclLinkageAndVisibility
(lib/AST/Decl.cpp) for N::S2<void> is that getExplicitVisibilityAux is called
on that ClassTemplateSpecializationDecl, so calls
<span class="quote">> return getVisibilityOf(spec->getSpecializedTemplate()->getTemplatedDecl(),
> kind);</span >
but that ->getTemplateDecl() points at a CXXRecordDecl that lacks the
TypeVisibilityAttr.
When you look at the -Xclang -ast-dump,
...
<span class="quote">> `-ClassTemplateSpecializationDecl 0x7fa7ef867358 <line:3:3, line:6:3> line:3:29 struct S1 definition
> |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
> | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
> | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
> | |-MoveConstructor exists simple trivial needs_implicit
> | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
> | |-MoveAssignment exists simple trivial needs_implicit
> | `-Destructor simple irrelevant trivial
> |-TemplateArgument type 'void'
> |-CXXRecordDecl 0x7fa7ef867d78 prev 0x7fa7ef867358 <col:22, col:29> col:29 implicit struct S1
> |-FriendDecl 0x7fa7ef867f98 <line:4:5, line:5:68> col:68
> | `-ClassTemplateDecl 0x7fa7ef867f28 parent 0x7fa7ef8348f0 prev 0x7fa7ef8353e8 <line:4:5, line:5:68> col:68 S2
> | |-TemplateTypeParmDecl 0x7fa7ef867e10 <line:4:14> col:14 typename depth 0 index 0
> | |-CXXRecordDecl 0x7fa7ef867e90 parent 0x7fa7ef8348f0 prev 0x7fa7ef835350 <line:5:12, col:68> col:68 struct S2
> | |-ClassTemplateSpecialization 0x7fa7ef8676b0 'S2'
> | `-ClassTemplateSpecialization 0x7fa7ef86aa00 'S2'
> `-CXXDestructorDecl 0x7fa7ef868018 <line:3:29> col:29 implicit referenced ~S1 'void () noexcept' inline default trivial</span >
...
there is a specialization of N::S1<void> with a FriendDecl/CXXRecordDecl for S2
lacking the TypeVisibilityAttr, and I think that's the instance that the above
->getTemplateDecl() points at. What I don't know is whether the bug is that
that FriendDecl/CXXRecordDecl for S2 lacks the TypeVisibilityAttr, or that the
above ->getTemplateDecl() points at that specific FriendDecl/CXXRecordDecl
(there are further CXXRecordDecls for S2 in the AST dump, with a proper
TypeVisibilityAttr).</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>