[Bug fortran/47069] [OOP] undefined reference for virtual hook

2010-12-27 Thread janus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47069

--- Comment #1 from janus at gcc dot gnu.org 2010-12-27 17:57:48 UTC ---
(In reply to comment #0)
 The code below fails to compile due to an undefined reference to the virtual
 hook. I have no idea if this is valid Fortran of any standard, but if it 
 isn't,
 I'd expect a warning or an error, if it is, I'd like to have an executable
 program :)

Well, what you get is a linker error, and don't think the standard covers
anything related to linking.

Therefore I would not call your program 'invalid' in a strict sense. However, I
think the error you get is not a bug in gfortran, but rather something like a
user error: You make the following call ...

 this%a = init_hook(this, n)

but you don't provide any stand-alone routine called 'init_hook'. Therefore you
get a linker error, and you deserve it ;)

What you probably want to do is

this%a = this%init_hook(n)

If I change the call in this way, your test case compiles and links fine. The
point here is that your 'init_hook' is a deferred type-bound procedure which
you can only call as bound to a type, i.e. via the % notation.

In contrast, 'init' is also a type-bound procedure, but it exists as a
'stand-alone' standard subroutine, too. So in this case you have two options to
call it:

1) directly: call init(this,n)
2) via its type binding: call this%init(n)

At least this is my view of these things, which I hope is correct. My
conclusion would be to close this bug as invalid, since it can not see anything
wrong in gfortran's behavior here. Also I don't think it's possible to give a
better error message for this case. The compiler simply cannot read your mind
...


[Bug fortran/47069] [OOP] undefined reference for virtual hook

2010-12-27 Thread dfranke at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47069

Daniel Franke dfranke at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #2 from Daniel Franke dfranke at gcc dot gnu.org 2010-12-27 
18:27:44 UTC ---
(In reply to comment #1)
 Therefore you get a linker error, and you deserve it ;)
 What you probably want to do is
 this%a = this%init_hook(n)

Oh my bloody stupidness! Of course!
A C++-ism that crept in - and I looked at it for ... hours ... *blush*

Closing as invalid. Thanks for the pointer and I apologize for the noise.