public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/55758] New: LOGICAL and BIND(C): Reject kind=2/4/8/16 with -std=f2008, improve warning, switch to nonBOOLEAN_TYPE for those
@ 2012-12-20 15:07 burnus at gcc dot gnu.org
  2013-01-09 16:21 ` [Bug fortran/55758] " 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-12-20 15:07 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: burnus@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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-05 10:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-20 15:07 [Bug fortran/55758] New: LOGICAL and BIND(C): Reject kind=2/4/8/16 with -std=f2008, improve warning, switch to nonBOOLEAN_TYPE for those burnus at gcc dot gnu.org
2013-01-09 16:21 ` [Bug fortran/55758] " burnus at gcc dot gnu.org
2013-02-26 14:41 ` burnus at gcc dot gnu.org
2014-03-22 19:22 ` dominiq at lps dot ens.fr
2015-09-05 10:31 ` dominiq at lps dot ens.fr

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).