This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/57305] [OOP] ICE when calling SIZEOF on an unlimited polymorphic variable
- From: "janus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 21 Aug 2013 13:53:04 +0000
- Subject: [Bug fortran/57305] [OOP] ICE when calling SIZEOF on an unlimited polymorphic variable
- Auto-submitted: auto-generated
- References: <bug-57305-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57305
--- Comment #6 from janus at gcc dot gnu.org ---
(In reply to janus from comment #5)
> The ICE on comment 1 seems to be due to the SIZEOF call.
... which is basically because SIZEOF is supposed to return the size of the
declared type, and a CLASS(*) doesn't really have a declared type, cf. also
http://gcc.gnu.org/onlinedocs/gfortran/SIZEOF.html
Of course SIZEOF is a GNU extension, so we are free to define its behavior in
any way we please. I don't remember why it was chosen to take the size of the
declared type back in the day. When it was implemented for polymorphics,
CLASS(*) was not yet available in gfortran.
One way out: You could use STORAGE_SIZE, which is standard F08 and returns the
size of the *dynamic* type. Also it seems to work well with CLASS(*).
In any case the ICE should be fixed by one of the following approaches:
1) reject SIZEOF on CLASS(*)
2) make it return 0 for CLASS(*)
3) make it return the size of the dynamic type
Option #3 is probably what you were expecting, right? I don't see any reason
for not going this route, except that changing behavior is bad in general. But
if it fixes an ICE, I guess it's not that bad after all ...