[kde-solaris] sizeof() doesn't bind to pointers to template parameter types
Adriaan de Groot
groot at kde.org
Sat Aug 18 23:03:04 CEST 2007
The following 4-liner causes an assert in Studio 12:
template<typename T> struct Exam {
static const unsigned int s = sizeof(T*);
} ;
class A;
Exam<A> s;
Replacing sizeof(T*) by sizeof(void*) avoids the assert. I deduce that
sizeof() doesn't bind properly to the template parameter T. This is annoying,
especially in WebKit which is full of that kind of template magic. I am
patching it locally to replace all sizeof(T*) by sizeof(void*) which I'm not
sure is 100% correct from a C++ standard point of view (ISTR that pointers to
different types are allowed to be different sizes).
It's a compiler bug, regardless.
Let's replace the sizeof(T*) with sizeof(PTR_TYPE*) and watch what happens
with different values for PTR_TYPE -- Bogus, the template type T and void:
-bash-3.00$ CC -DPTR_TYPE=Bogus t.cc
"t.cc", line 2: Error: Bogus is not defined.
"t.cc", line 7: Where: While specializing "Exam<A*>".
-bash-3.00$ CC -DPTR_TYPE=T t.cc
>> Assertion: (../lnk/bind.cc, line 268)
while processing t.cc at line 7.
-bash-3.00$ CC -DPTR_TYPE=void t.cc
Good, ugly, good.
Since I'm running nv_64 with CC: Sun C++ 5.9 SunOS_i386 2007/05/03 I'm not
sure if this is worth filing a bug over; it might be fixed already.
--
These are your friends - Adem
GPG: FEA2 A3FE Adriaan de Groot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kde-solaris/attachments/20070818/15229909/attachment.pgp
More information about the kde-solaris
mailing list