- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
the following code is miscompiled by ifort/ifx:
module m
implicit none
interface operator (==)
module procedure star_eq
end interface
contains
function star_eq(a, b)
class(*), intent(in) :: a, b
integer :: star_eq
star_eq = 42
end function star_eq
end
program p
use m
implicit none
character :: c = 'a'
print *, ('a' == 'a') ! expect: T
print *, ('a' == c ) ! expect: T
print *, ( c == c ) ! expect: T
end
I get here:
% ifx -what ifort-wrong-interface.f90 && ./a.out
Intel(R) Fortran 23.0-1769.01
42
42
42
Note that NAG prints 3 lines with "T", as expected.
Ifort/ifx appears to ignore that in the present situation the compiler must choose the intrinsic
comparison operator since the arguments are consistent with F2018:10.1.5.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
perhaps this is one of the few cases where NAG is wrong.
module c
contains
function character_eq_character(a,b)
character(len=*), intent(in) :: a, b
logical :: character_eq_character
character_eq_character = (a==b)
end function character_eq_character
function integer_eq_integer(a,b)
integer, intent(in) :: a, b
logical :: integer_eq_integer
integer_eq_integer = (a==b)
end function integer_eq_integer
end module c
module m
implicit none
interface operator (==)
module procedure star_eq
end interface
contains
function star_eq(a, b)
use c
class(*), intent(in) :: a, b
logical :: star_eq
select type(a)
class is (character(len=*))
select type(b)
class is (character(len=*))
star_eq = character_eq_character(a,b)
class default
star_eq = .false.
end select
class is (integer)
select type(b)
class is (integer)
star_eq = integer_eq_integer(a,b)
class default
star_eq = .false.
end select
class default
star_eq = .false.
end select
end function star_eq
end
program p
use m
implicit none
character :: c = 'a'
print *, ('a' == 'a') ! expect: T
print *, ('a' == c ) ! expect: T
print *, ( c == c ) ! expect: T
print *, ('a' == 'b') ! expect: F
print *, ('a' == 1) ! expect: F
print *, (1 == 2) ! expect: F
print *, (1 == 1) ! expect: T
end
output:
T
T
T
F
F
F
T
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can fill in the other permutations.
Jim Dempsey
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page