public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
@ 2012-05-06 8:55 burnus at gcc dot gnu.org
2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-06 8:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53255
Bug #: 53255
Summary: [OOP] With TYPE, wrong type-bound operator used: of
parent instead of overridden one
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: burnus@gcc.gnu.org
Reported by Reinhold Bader.
Expected: The following output:
executing base
executing override
OK
De-facto output:
executing base
executing base
FAIL
If one changes:
type(ext) :: p
to
class(ext), allocatable :: p
allocate(p)
or
class(base), allocatable :: p
allocate(ext :: p)
it works.
Thus, it seems as if only the compile-time resolution of TYPE has the problem,
while the vtable run-time version is correct.
module mod_base
implicit none
private
type, public :: base
private
real :: r(2,2) = reshape( (/ 1.0, 2.0, 3.0, 4.0 /), (/ 2, 2 /))
contains
procedure, private :: trace
generic :: operator(.tr.) => trace
end type base
contains
complex function trace(this)
class(base), intent(in) :: this
trace = this%r(1,1) + this%r(2,2)
end function trace
end module mod_base
module mod_ext
use mod_base
implicit none
private
public :: base
type, public, extends(base) :: ext
private
real :: i(2,2) = reshape( (/ 1.0, 1.0, 1.0, 1.5 /), (/ 2, 2 /))
contains
procedure, private :: trace => trace_ext
end type ext
contains
complex function trace_ext(this)
class(ext), intent(in) :: this
! the following should be executed through invoking .tr. p below
write(*,*) 'executing override'
trace_ext = .tr. this%base + (0.0, 1.0) * ( this%i(1,1) + this%i(2,2) )
end function trace_ext
end module mod_ext
program test_override
use mod_ext
implicit none
type(base) :: o
type(ext) :: p
! write(*,*) .tr. o
! write(*,*) .tr. p
if (abs(.tr. o - 5.0 ) < 1.0e-6 .and. abs( .tr. p - (5.0,2.5)) < 1.0e-6)
then
write(*,*) 'OK'
else
write(*,*) 'FAIL'
end if
end program test_override
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53255] [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
2012-05-06 8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
@ 2012-05-06 10:33 ` burnus at gcc dot gnu.org
2012-05-07 8:44 ` burnus at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-06 10:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53255
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |burnus at gcc dot gnu.org,
| |janus at gcc dot gnu.org
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-06 08:54:29 UTC ---
What happens is the call to resolve_compcall, which in turn calls
resolve_typebound_generic_call. That procedure fails as
e->value.compcall.tbp->is_generic == false. I think that's okay as only .tr. is
generic, the "trace" is not.
However, somewhere in resolve_compcall or resolve_typebound_static it should
search for the overridden procedure.
The following seems to work. Janus: Do you think that the patch makes sense?
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -5671,9 +5702,8 @@ resolve_typebound_static (gfc_expr* e, gfc_symtree**
target,
e->value.compcall.actual = NULL;
/* If we find a deferred typebound procedure, check for derived types
- that an over-riding typebound procedure has not been missed. */
- if (e->value.compcall.tbp->deferred
- && e->value.compcall.name
+ that an overriding typebound procedure has not been missed. */
+ if (e->value.compcall.name
&& !e->value.compcall.tbp->non_overridable
&& e->value.compcall.base_object
&& e->value.compcall.base_object->ts.type == BT_DERIVED)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53255] [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
2012-05-06 8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
@ 2012-05-07 8:44 ` burnus at gcc dot gnu.org
2012-05-07 11:52 ` burnus at gcc dot gnu.org
2012-05-07 13:35 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-07 8:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53255
--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-07 08:35:21 UTC ---
Author: burnus
Date: Mon May 7 08:35:17 2012
New Revision: 187226
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187226
Log:
2012-05-07 Tobias Burnus <burnus@net-b.de>
PR fortran/53255
* resolve.c (resolve_typebound_static): Fix handling
of overridden specific to generic operator.
2012-05-07 Tobias Burnus <burnus@net-b.de>
PR fortran/53255
* gfortran.dg/typebound_operator_15.f90: New.
Added:
trunk/gcc/testsuite/gfortran.dg/typebound_operator_15.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53255] [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
2012-05-06 8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
2012-05-07 8:44 ` burnus at gcc dot gnu.org
@ 2012-05-07 11:52 ` burnus at gcc dot gnu.org
2012-05-07 13:35 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-07 11:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53255
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-07 11:50:12 UTC ---
Author: burnus
Date: Mon May 7 11:50:04 2012
New Revision: 187232
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187232
Log:
2012-05-07 Tobias Burnus <burnus@net-b.de>
Backport from mainline:
2012-05-07 Tobias Burnus <burnus@net-b.de>
PR fortran/53255
* resolve.c (resolve_typebound_static): Fix handling
of overridden specific to generic operator.
2012-05-07 Tobias Burnus <burnus@net-b.de>
Backport from mainline:
2012-05-07 Tobias Burnus <burnus@net-b.de>
PR fortran/53255
* gfortran.dg/typebound_operator_15.f90: New.
Added:
branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/typebound_operator_15.f90
Modified:
branches/gcc-4_7-branch/gcc/fortran/ChangeLog
branches/gcc-4_7-branch/gcc/fortran/resolve.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug fortran/53255] [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one
2012-05-06 8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
` (2 preceding siblings ...)
2012-05-07 11:52 ` burnus at gcc dot gnu.org
@ 2012-05-07 13:35 ` burnus at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-05-07 13:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53255
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-05-07 13:33:08 UTC ---
FIXED on the trunk (4.8) and on the 4.7 branch.
4.5 and 4.6 are also affected, but already for 4.6 the code is too different
for a simple back porting. As the OOP support in 4.7/4.8 is much better,
4.5/4.6 shouldn't be used for polymorphism application at all.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-05-07 13:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-06 8:55 [Bug fortran/53255] New: [OOP] With TYPE, wrong type-bound operator used: of parent instead of overridden one burnus at gcc dot gnu.org
2012-05-06 10:33 ` [Bug fortran/53255] " burnus at gcc dot gnu.org
2012-05-07 8:44 ` burnus at gcc dot gnu.org
2012-05-07 11:52 ` burnus at gcc dot gnu.org
2012-05-07 13:35 ` burnus at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).