<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Fails to merge templated static member variables"
href="https://llvm.org/bugs/show_bug.cgi?id=26179">26179</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Fails to merge templated static member variables
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Modules
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>vvasilev@cern.ch
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>My diagnosis is:
template<typename T> struct basic_string {
static T _S_empty_rep_storage[]; // #1
};
template<typename T> T basic_string<T>::_S_empty_rep_storage[sizeof(T)]; // #2
#1 and #2 end up on the same redecl chain. #2 gets registered in the lookup
table and when isSameEntity compares the type of the imported VarDecl
(essentially #1 coming from another module) it finds a mismatch.
A fix to this issue is just dialing Existing->getCanonicalDecl. There are two
questions I cannot answer (yet?):
1. Should #2 really end up in the redecl chain, it looks like a different
decl (at least when it comes to types, true that both are
IncompleteArrayTypes]?
2. Why #2 ended up in the lookup table when #1 was seen before?
3. Where should the fix go:
a) should it be isSameEntity(Existing->getCanonicalDecl(), D) -
semantically #2 cannot end up as a canonical decl.
b) should I extend the logic (somehow) of isSameEntity (VarDecl section)?
2872 DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
2873 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I
!= E; ++I) {
2874 if (NamedDecl *Existing = getDeclForMerging(*I,
TypedefNameForLinkage))
-> 2875 if (isSameEntity(Existing, D))
2876 return FindExistingResult(Reader, D, Existing,
AnonymousDeclNumber,
2877 TypedefNameForLinkage);
2878 }
(lldb) p Existing
(clang::VarDecl *) $186 = 0x000000010c831390
(lldb) p Existing->dump()
VarDecl 0x10c831390 parent 0x10c051530 prev 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:9:1,
line:10:50> col:20 _S_empty_rep_storage 'T [sizeof(T)]'
(lldb) p Existing->getPreviousDecl()
(clang::VarDecl *) $187 = 0x000000010c830fa8
(lldb) p Existing->getPreviousDecl()->dump()
VarDecl 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:3,
col:33> col:12 _S_empty_rep_storage 'T []' static
(lldb) p Existing->getPreviousDecl()->getPreviousDecl()
(clang::Decl *) $188 = 0x0000000000000000
(lldb) p Existing->getMostRecentDecl()
(clang::VarDecl *) $189 = 0x000000010c831390
(lldb) p Existing->getCanonicalDecl()
(clang::VarDecl *) $190 = 0x000000010c830fa8
(lldb) p Existing->getCanonicalDecl()->dump()
VarDecl 0x10c830fa8
</Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:3,
col:33> col:12 _S_empty_rep_storage 'T []' static
The error message is:
In module 'B' imported from
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/A.h:5:
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:12:
error: 'basic_string::_S_empty_rep_storage' from module 'B' is not present in
definition of 'basic_string<T>' provided earlier
static T _S_empty_rep_storage[];
^
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/Inputs/PRN/basic_string.h:6:12:
note: declaration of '_S_empty_rep_storage' does not match
static T _S_empty_rep_storage[];
^
/Users/vvassilev/workspace/llvm-git/src/tools/clang/test/Modules/prN.cpp:5:10:
fatal error: could not build module 'A'
#include "A.h"
~~~~~~~~^~~~~
2 errors generated.</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>