sizeof() doesn't bind to pointers to template parameter types
Adriaan de Groot <[email protected]>
| Newsgroups | gmane.comp.kde.solaris |
|---|---|
| Message-ID | <[email protected]> |
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
___________________________________________________
This message is from the kde-solaris mailing list.
Account management: https://mail.kde.org/mailman/listinfo/kde-solaris.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.
signature.asc
(application/pgp-signature, 187 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQBGx16JdqzuAf6io/4RAk8rAJ9L2JcH/90VFZEzunBhMfAegJn84ACeKbgv t4TIX8M1i2YCSClQALJIUgM= =SQH0 -----END PGP SIGNATURE-----