http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55758



             Bug #: 55758

           Summary: LOGICAL and BIND(C): Reject kind=2/4/8/16 with

                    -std=f2008, improve warning, switch to nonBOOLEAN_TYPE

                    for those

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Keywords: accepts-invalid, diagnostic

          Severity: normal

          Priority: P3

         Component: fortran

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: bur...@gcc.gnu.org





See http://gcc.gnu.org/ml/fortran/2012-12/threads.html#00135



In the Fortran standard, only LOGICALs of kind C_BOOL interoperate with C;

namely, with C99's _Bool/bool.



In C, also integers - in particular "int" - are used in Boolean expressions,

allows for the whole range of integral values - all are "true" except for 0

which is "false".



gcc's _Bool and gfortran's LOGICAL all assume a binary state (BOOLEAN_TYPE)

which is either 0 or 1 such that .NOT. can be implemented by flipping a single

bit.



Hence, regarding an "int" as BOOLEAN_TYPE leads to .NOT.(-1) = -2.





Currently, LOGICAL(kind=C_INT) (c_int == 4) is accepted by gfortran and C

binding, but it might lead to wrong results with .NOT.





Expected:

* With -std=f95/f2003/f2008/f2008tr, only LOGICAL with kind=C_BOOL (C_BOOL ==

1) is accepted

* With -std=gnu, also the others (2,4,8,16) are accepted but a warning is

printed for them.

* Consider replacing internally BOOLEAN_TYPE by a signed-integer type LOGICAL

with kind /= C_BOOL in procedures with C binding

Reply via email to