<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 - Partial specialization halfway accepted after instantiation"
href="https://bugs.llvm.org/show_bug.cgi?id=38234">38234</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Partial specialization halfway accepted after instantiation
</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>Linux
</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>zhonghao@pku.org.cn
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following code produces predictable but odd output. The compiler should
either generate a warning for this case or throw away the instantiation of the
type upon encountering the better-matching partial specialization, somehow
keeping it for code above the given line.
template <typename T>
struct A {
T o;
};
int sizeofa = sizeof(A<int *>);
template <typename T>
struct A<T *> {
T o[5];
};
int newsizeofa = sizeof(A<int *>);
int main() {
printf("%d, %d, %d\n", sizeofa, sizeof(A<int *>), sizeof(A<double *>));
}
The given output is 8, 8, 40. It appears that the specialization is accepted
for any type not yet instantiated.
I tried g++. It produces an error message:
code1.cpp:12:8: error: partial specialization of 'struct A<T*>' after
instantiation of 'struct A<int*>' [-fpermissive]
struct A<T *> {
^~~~~~
A simpler testcase:
template <class T> struct A { };
A<int*> a;
template <class T> struct A<T*> { }; // { dg-error "A<int *>" }</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>