[Bug fortran/62176] [OOP] Inconsistent resolution of GENERIC interface
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62176 janus at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED CC||janus at gcc dot gnu.org Resolution|--- |INVALID --- Comment #3 from janus at gcc dot gnu.org --- (In reply to Dominique d'Humieres from comment #1) > Reduced test > [...] > > The code compiles if the lines > > generic :: lle => string_less_equal_char, & > char_less_equal_string > > are commented. I cannot see how 'string_less_equal_char' and > 'char_less_equal_string' are ambiguous for 'lle', but not for operator '<='. Well, that's simply due to the different invocation syntax for both cases. 1) For the type-bound generic 'lle', the call looks like this: str%lle(ch) This matches both specific TBPs (which only differ in the position of the PASS argument), therefore they are ambiguous in this context. 2) The operator '<=' is invoked by one of the two forms: str <= ch ch <= str Here both specifics can be distinguished, so they are not ambiguous. In summary, gfortran's behavior is perfectly fine. This is a non-bug.
[Bug fortran/62176] [OOP] Inconsistent resolution of GENERIC interface
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62176 --- Comment #2 from Dominique d'Humieres --- As shown by pr64138 and the links therein, disambiguation of procedures by argument position is tricky. This does not change the fact that the behavior should be the same for, e.g., 'lle' and '<='. Also the following code module m_string implicit none type t_string character, dimension(:), allocatable :: buffer integer :: length = 0 integer :: size = 0 contains ! Interfaces for string types generic :: character => string_to_char procedure :: string_to_char ! Element comparison operators procedure :: string_less_equal_char procedure, pass(right1) :: char_less_equal_string generic :: operator(<=) => string_less_equal_char, & char_less_equal_string ! Character compatibility interfaces generic :: lle => string_less_equal_char, & char_less_equal_string end type t_string contains ! Return the string as character pure function string_to_char( this ) result(res) class(t_string), intent(in) :: this character(len=this%size) :: res if( allocated(this%buffer) ) then res = transfer( this%buffer(:this%size), res ) else res = '' end if end function string_to_char ! Comparison operator 'string <= character' elemental function string_less_equal_char( left, right ) result(res) class(t_string), intent(in) :: left character(len=*), intent(in) :: right logical :: res res = ( left%character() <= right ) end function string_less_equal_char ! Comparison operator 'character <= string' elemental function char_less_equal_string( left1, right1 ) result(res) character(len=*), intent(in) :: left1 class(t_string), intent(in) :: right1 logical :: res res = ( left1 <= right1%character() ) end function char_less_equal_string end module m_string still gives Error: 'string_less_equal_char' and 'char_less_equal_string' for GENERIC 'lle' at (1) are ambiguous
[Bug fortran/62176] [OOP] Inconsistent resolution of GENERIC interface
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62176 Dominique d'Humieres changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2014-08-20 Ever confirmed|0 |1 --- Comment #1 from Dominique d'Humieres --- Reduced test module m_string implicit none type t_string character, dimension(:), allocatable :: buffer integer :: length = 0 integer :: size = 0 contains ! Interfaces for string types generic :: character => string_to_char procedure :: string_to_char ! Element comparison operators procedure :: string_less_equal_char procedure, pass(right) :: char_less_equal_string generic :: operator(<=) => string_less_equal_char, & char_less_equal_string ! Character compatibility interfaces generic :: lle => string_less_equal_char, & char_less_equal_string end type t_string contains ! Return the string as character pure function string_to_char( this ) result(res) class(t_string), intent(in) :: this character(len=this%size) :: res if( allocated(this%buffer) ) then res = transfer( this%buffer(:this%size), res ) else res = '' end if end function string_to_char ! Comparison operator 'string <= character' elemental function string_less_equal_char( left, right ) result(res) class(t_string), intent(in) :: left character(len=*), intent(in) :: right logical :: res res = ( left%character() <= right ) end function string_less_equal_char ! Comparison operator 'character <= string' elemental function char_less_equal_string( left, right ) result(res) character(len=*), intent(in) :: left class(t_string), intent(in) :: right logical :: res res = ( left <= right%character() ) end function char_less_equal_string end module m_string The code compiles if the lines generic :: lle => string_less_equal_char, & char_less_equal_string are commented. I cannot see how 'string_less_equal_char' and 'char_less_equal_string' are ambiguous for 'lle', but not for operator '<='.