static void write_type (gfc_symbol *sym);
static void write_funptr_fcn (gfc_symbol *);
+/* Helper function determining if the characteristics of a formal argument of a
+ bind(C) procedure is such that its C prototype needs struct CFI_cdesc_t. */
+
+static bool
+needs_CFI_cdesc (gfc_typespec *ts, gfc_array_spec *as)
+{
+ return ((as && (as->type == AS_ASSUMED_RANK
+ || as->type == AS_ASSUMED_SHAPE
+ || as->type == AS_DEFERRED))
+ || (ts->type == BT_CHARACTER
+ && (ts->deferred || ts->u.cl->length == NULL)));
+}
+
/* Do we need to write out an #include <ISO_Fortran_binding.h> or not? */
static void
{
gfc_symbol *s;
s = f->sym;
- if (s->as && (s->as->type == AS_ASSUMED_RANK || s->as->type == AS_ASSUMED_SHAPE))
+ if (needs_CFI_cdesc (&s->ts, s->as))
{
*data_p = true;
return;
*post = "";
*type_name = "<error>";
- if ((as && (as->type == AS_ASSUMED_RANK
- || as->type == AS_ASSUMED_SHAPE
- || as->type == AS_DEFERRED))
- || (ts->type == BT_CHARACTER
- && (ts->deferred || ts->u.cl->length == NULL)))
+ if (needs_CFI_cdesc (ts, as))
{
*asterisk = true;
*post = "";
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fc-prototypes" }
+!
+! PR fortran/125902
+!
+! Test -fc-prototypes for assumed length character dummy, header include
+
+subroutine sub (b) bind(C)
+ character(*) :: b
+end subroutine sub
+
+#if 0
+!{ dg-begin-multiline-output "" }
+#include <stddef.h>
+#ifdef __cplusplus
+#include <complex>
+#define __GFORTRAN_FLOAT_COMPLEX std::complex<float>
+#define __GFORTRAN_DOUBLE_COMPLEX std::complex<double>
+#define __GFORTRAN_LONG_DOUBLE_COMPLEX std::complex<long double>
+extern "C" {
+#else
+#define __GFORTRAN_FLOAT_COMPLEX float _Complex
+#define __GFORTRAN_DOUBLE_COMPLEX double _Complex
+#define __GFORTRAN_LONG_DOUBLE_COMPLEX long double _Complex
+#endif
+
+#include <ISO_Fortran_binding.h>
+
+void sub (CFI_cdesc_t *b);
+
+#ifdef __cplusplus
+}
+#endif
+!{ dg-end-multiline-output "" }
+#endif