gfortran printed an error that "c_null_ptr" couldn't be SAVE an
PARAMETER at the same time; removing the SAVE attribute causes an error
that a BIND(C) variable may not be a PARAMETER, thus that has to be
fixed as well.
(Patch based on the one of Steven
Build and regtested on x86-64-linux.
OK for the trunk?
Tobias
2011-11-28 Tobias Burnus <bur...@net-b.de>
Steven G. Kargl <ka...@gcc.gnu.org>
PR fortran/51308
* symbol.c (check_conflict): Ignore BIND(C) + PARAMETER
conflicts for ISO_C_BINDING variables.
(gen_special_c_interop_ptr): Don't mark c_ptr_null/c_funptr_null
as SAVE.
2011-11-28 Tobias Burnus <bur...@net-b.de>
PR fortran/51308
* gfortran.dg/iso_c_binding_compiler_4.f90: New.
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 9bd6ed4..67009c5 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -742,9 +742,10 @@ check_conflict (symbol_attribute *attr, const char *name, locus *where)
conf2 (asynchronous);
conf2 (threadprivate);
conf2 (value);
- conf2 (is_bind_c);
conf2 (codimension);
conf2 (result);
+ if (!attr->is_iso_c)
+ conf2 (is_bind_c);
break;
default:
@@ -3763,13 +3764,12 @@ gen_special_c_interop_ptr (int ptr_id, const char *ptr_name,
"create symbol for %s", ptr_name);
}
- /* Set up the symbol's important fields. Save attr required so we can
- initialize the ptr to NULL. */
- tmp_sym->attr.save = SAVE_EXPLICIT;
+ /* Set up the symbol's important fields. */
tmp_sym->ts.is_c_interop = 1;
tmp_sym->attr.is_c_interop = 1;
tmp_sym->ts.is_iso_c = 1;
tmp_sym->ts.type = BT_DERIVED;
+ tmp_sym->attr.flavor = FL_PARAMETER;
/* The c_ptr and c_funptr derived types will provide the
definition for c_null_ptr and c_null_funptr, respectively. */
@@ -3817,9 +3817,6 @@ gen_special_c_interop_ptr (int ptr_id, const char *ptr_name,
c->expr = gfc_get_expr ();
c->expr->expr_type = EXPR_NULL;
c->expr->ts.is_iso_c = 1;
- /* Must declare c_null_ptr and c_null_funptr as having the
- PARAMETER attribute so they can be used in init expressions. */
- tmp_sym->attr.flavor = FL_PARAMETER;
return SUCCESS;
}
--- /dev/null 2011-11-28 07:33:54.995528670 +0100
+++ gcc/gcc/testsuite/gfortran.dg/iso_c_binding_compiler_4.f90 2011-11-28 14:27:05.000000000 +0100
@@ -0,0 +1,18 @@
+! { dg-do compile }
+!
+! PR fortran/51308
+!
+! Contributed by Matthias Moeller
+!
+
+module mymod
+ use iso_c_binding
+ implicit none
+
+ private
+ public :: c_ptr
+ public :: c_null_ptr
+
+end module mymod
+
+! { dg-final { cleanup-modules "mymod" } }