[llvm-bugs] [Bug 38234] New: Partial specialization halfway accepted after instantiation
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jul 19 18:11:23 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38234
Bug ID: 38234
Summary: Partial specialization halfway accepted after
instantiation
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: zhonghao at pku.org.cn
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
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 *>" }
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180720/a21941e5/attachment.html>
More information about the llvm-bugs
mailing list