Silverfrost Forums

Welcome to our forums

interface operators

5 Mar 2013 5:24 #11654

The following program defines two interface operators (both ==) for separate derived types. They are defined in separate modules, but the second module uses the derived type in the first module for some independent reason. The use creates a warning message that I am nto quite sure how to interpret. It seems to imply that I cannot use the first interface operator in module 2. Any advice on what might be happening here would be greatly appreciated.

MODULE m1
  TYPE type1
   INTEGER :: i1
   INTEGER :: i2
  END TYPE type1
  INTERFACE OPERATOR(==)
     MODULE PROCEDURE same1
  END INTERFACE
CONTAINS
 FUNCTION same1(t1a,t1b)
  LOGICAL :: same1
  TYPE(type1), INTENT(IN) :: t1a
  TYPE(type1), INTENT(IN) :: t1b
  IF ((t1a%i1==t1b%i1).AND.(t1a%i2==t1b%i2)) THEN
     same1=.true.
  ELSE
     same1=.false.
  ENDIF
 END FUNCTION same1
END MODULE m1
!
MODULE m2
  USE m1, ONLY: type1
  TYPE type2
   INTEGER :: i1
   INTEGER :: i2
   INTEGER :: i3
  END TYPE type2
  PUBLIC :: OPERATOR(==)
  INTERFACE OPERATOR(==)
     MODULE PROCEDURE same2
  END INTERFACE
CONTAINS
 FUNCTION same2(t2a,t2b)
  LOGICAL :: same2
  TYPE(type2), INTENT(IN) :: t2a
  TYPE(type2), INTENT(IN) :: t2b
  IF ((t2a%i1==t2b%i1).AND.(t2a%i2==t2b%i2).AND.(t2a%i3==t2b%i3)) THEN
     same2=.true.
  ELSE
     same2=.false.
  ENDIF
 END FUNCTION same2
END MODULE m2
5 Mar 2013 9:06 #11657

This looks like a false warning message. Does it work if you ignore the warning? I have logged this for investigation.

5 Mar 2013 2:54 #11661

Thanks Paul. I think the program works anyway, I don't think this particular problem has been creating any run-time problems, but I've been struggling to clear up some other module conflicts and wasn't sure if I was making some obscure programming error in this instance.

9 Apr 2013 2:46 #12003

I have had a look at this and I don't think there is a problem here.

The compiler just thinks that you may have made a mistake and flags up a warning.

If you remove the redundant 'PUBLIC' statement then the warning does not appear.

9 Apr 2013 4:13 #12007

The use of PUBLIC OPERATOR(=) in M2 might be necessary if M2 contains a PRIVATE statement (I know its redundant in this case).

I would suggest this warning is associated with the issue identified in this other thread.

https://forums.silverfrost.com/Forum/Topic/1754&start=15

In simon's code above, the intention is that OPERATOR(=) in M1 should not be being used so there shouldn't be a conflict with the OPERATOR(=) in M2. If you comment out the USE statement which is also redundant, the code compiles with no warnings.

If you fix the issue with ONLY, in the other thread then this bug will also disappear I think.

So fix the other bug and see what happens with this one. 😃

10 Apr 2013 9:03 #12035

David is correct - although it is redundant in the example, I do need the PUBLIC statement because in my larger module I have a PRIVATE statement. Plus I need the USE statement even though it is redundant here.

10 Apr 2013 9:28 #12037

If the warning is a nuisance then you can use /ignore 928 on the command line to suppress it.

Please login to reply.