otherwise, it is set to NULL. The msg string can be used in diagnostics.
If c_loc is true, character with len > 1 are allowed (cf. Fortran
2003corr5); additionally, assumed-shape/assumed-rank/deferred-shape
- arrays are permitted. */
+ arrays are permitted. And if c_f_ptr is true, deferred-shape arrays
+ are permitted. */
static bool
-is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc)
+is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
{
*msg = NULL;
*msg = "Only whole-arrays are interoperable";
return false;
}
- if (ar->as->type != AS_EXPLICIT && ar->as->type != AS_ASSUMED_SIZE)
+ if (!c_f_ptr && ar->as->type != AS_EXPLICIT
+ && ar->as->type != AS_ASSUMED_SIZE)
{
*msg = "Only explicit-size and assumed-size arrays are interoperable";
return false;
{
const char *msg;
- if (!is_c_interoperable (arg, &msg, false))
+ if (!is_c_interoperable (arg, &msg, false, false))
{
gfc_error ("'%s' argument of '%s' intrinsic at %L must be an "
"interoperable data entity: %s",
return false;
}
- if (!is_c_interoperable (fptr, &msg, false) && fptr->rank)
+ if (!is_c_interoperable (fptr, &msg, false, true))
return gfc_notify_std (GFC_STD_F2008_TS, "Noninteroperable array FPTR "
"at %L to C_F_POINTER: %s", &fptr->where, msg);
return false;
}
- if (!is_c_interoperable (x, &msg, true))
+ if (!is_c_interoperable (x, &msg, true, false))
{
if (x->ts.type == BT_CLASS)
{
--- /dev/null
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! PR fortran/57834
+!
+! (Gave a bogus warning before.)
+!
+program main
+
+ use iso_c_binding
+ use iso_fortran_env
+
+ implicit none
+
+ interface
+ function strerror(errno) bind(C, NAME = 'strerror')
+ import
+ type(C_PTR) :: strerror
+ integer(C_INT), value :: errno
+ end function
+ end interface
+
+ integer :: i
+ type(C_PTR) :: cptr
+ character(KIND=C_CHAR), pointer :: str(:)
+
+ cptr = strerror(INT(42, KIND = C_INT))
+ call C_F_POINTER(cptr, str, [255])
+
+ do i = 1, SIZE(str)
+ if (str(i) == C_NULL_CHAR) exit
+ write (ERROR_UNIT, '(A1)', ADVANCE = 'NO') str(i:i)
+ enddo
+
+ write (ERROR_UNIT, '(1X)')
+
+end program main