From: Tobias Burnus Date: Fri, 6 May 2011 18:12:25 +0000 (+0200) Subject: re PR fortran/48858 (Incorrect error for same binding label on two generic interface... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2e8d9212daaa8c6162ab872485dd03d28c96ea4c;p=gcc.git re PR fortran/48858 (Incorrect error for same binding label on two generic interface specifics) 2011-05-06 Tobias Burnus PR fortran/48858 PR fortran/48820 * lang.opt (std=f2008tr): New. * libgfortran.h (GFC_STD_F2008_TR): New macro constant. * decl.c (verify_c_interop_param): Allow OPTIONAL in BIND(C) procedures for -std=f2008tr/gnu/legacy. 2011-05-06 Tobias Burnus PR fortran/48858 PR fortran/48820 * gfortran.dg/bind_c_usage_22.f90: New. * gfortran.dg/bind_c_usage_23.f90: New. * gfortran.dg/bind_c_usage_24.f90: New. * gfortran.dg/bind_c_usage_24_c.c: New. From-SVN: r173500 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index da6d2ab6331..e53be65e19d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2011-05-06 Tobias Burnus + + PR fortran/48858 + PR fortran/48820 + * lang.opt (std=f2008tr): New. + * libgfortran.h (GFC_STD_F2008_TR): New macro constant. + * decl.c (verify_c_interop_param): Allow OPTIONAL in BIND(C) + procedures for -std=f2008tr/gnu/legacy. + (gfc_match_import): Set sym to NULL. + * options.c (set_default_std_flags,gfc_handle_option): Handle + -std=f2008tr. + * invoke.texi (-std=): Document -std=f2008tr. + 2011-05-05 Nathan Froyd * trans-decl.c (gfc_trans_entry_master_switch): Call build_case_label. diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index dfbca29a479..8acd594f083 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -1060,14 +1060,22 @@ verify_c_interop_param (gfc_symbol *sym) retval = FAILURE; } - if (sym->attr.optional == 1) + if (sym->attr.optional == 1 && sym->attr.value) { - gfc_error ("Variable '%s' at %L cannot have the " - "OPTIONAL attribute because procedure '%s'" - " is BIND(C)", sym->name, &(sym->declared_at), + gfc_error ("Variable '%s' at %L cannot have both the OPTIONAL " + "and the VALUE attribute because procedure '%s' " + "is BIND(C)", sym->name, &(sym->declared_at), sym->ns->proc_name->name); retval = FAILURE; } + else if (sym->attr.optional == 1 + && gfc_notify_std (GFC_STD_F2008_TR, "TR29113: Variable '%s' " + "at %L with OPTIONAL attribute in " + "procedure '%s' which is BIND(C)", + sym->name, &(sym->declared_at), + sym->ns->proc_name->name) + == FAILURE) + retval = FAILURE; /* Make sure that if it has the dimension attribute, that it is either assumed size or explicit shape. */ @@ -2985,6 +2993,7 @@ gfc_match_import (void) for(;;) { + sym = NULL; m = gfc_match (" %n", name); switch (m) { diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index d24c2f28fba..9f022390b56 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -368,7 +368,9 @@ extensions, and may be useful for old non-standard programs. The conformance to the Fortran 95, Fortran 2003 and Fortran 2008 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features -that are permitted but obsolescent in later standards. +that are permitted but obsolescent in later standards. @samp{-std=f2008tr} +allows the Fortran 2008 standard including the additions of the +technical report (TR) 29113. @end table diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 015493e5ba6..ce944e3b4ce 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -590,6 +590,10 @@ std=f2008 Fortran Conform to the ISO Fortran 2008 standard +std=f2008tr +Fortran +Conform to the ISO Fortran 2008 standard including TR 29113 + std=f95 Fortran Conform to the ISO Fortran 95 standard diff --git a/gcc/fortran/libgfortran.h b/gcc/fortran/libgfortran.h index 09524d00357..035a32a7507 100644 --- a/gcc/fortran/libgfortran.h +++ b/gcc/fortran/libgfortran.h @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see Note that no features were obsoleted nor deleted in F2003. Please remember to keep those definitions in sync with gfortran.texi. */ +#define GFC_STD_F2008_TR (1<<9) /* POST-F2008 technical reports. */ #define GFC_STD_F2008_OBS (1<<8) /* Obsolescent in F2008. */ #define GFC_STD_F2008 (1<<7) /* New in F2008. */ #define GFC_STD_LEGACY (1<<6) /* Backward compatibility. */ diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index e27457233e5..c67d10916e9 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -49,7 +49,7 @@ set_default_std_flags (void) { gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 - | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY; + | GFC_STD_F2008_OBS | GFC_STD_F2008_TR | GFC_STD_GNU | GFC_STD_LEGACY; gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY; } @@ -945,6 +945,16 @@ gfc_handle_option (size_t scode, const char *arg, int value, gfc_option.warn_tabs = 0; break; + case OPT_std_f2008tr: + gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77 + | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS + | GFC_STD_F2008_TR; + gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS; + gfc_option.max_identifier_length = 63; + gfc_option.warn_ampersand = 1; + gfc_option.warn_tabs = 0; + break; + case OPT_std_gnu: set_default_std_flags (); break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3e89c93a159..66656f5ef62 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2011-05-06 Tobias Burnus + + PR fortran/48858 + PR fortran/48820 + * gfortran.dg/bind_c_usage_22.f90: New. + * gfortran.dg/bind_c_usage_23.f90: New. + * gfortran.dg/bind_c_usage_24.f90: New. + * gfortran.dg/bind_c_usage_24_c.c: New. + 2011-05-06 Dodji Seketeli PR c++/48838 diff --git a/gcc/testsuite/gfortran.dg/bind_c_usage_22.f90 b/gcc/testsuite/gfortran.dg/bind_c_usage_22.f90 new file mode 100644 index 00000000000..861f8c7cfd8 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_usage_22.f90 @@ -0,0 +1,64 @@ +! { dg-do compile } +! { dg-options "-std=f2008tr" } +! +! PR fortran/48858 +! PR fortran/48820 +! +! OPTIONAL + BIND(C) is allowed since TR 29113 +! + +! VALID +subroutine sub(z) bind(C) + use iso_c_binding + integer(c_int), value :: z +end subroutine sub + +! VALID since TR29113 +subroutine sub2(z) bind(C) + use iso_c_binding + integer(c_int), optional :: z +end subroutine sub2 + +! VALID since TR29113 +subroutine sub2a(z) bind(C) + use iso_c_binding + integer(c_int) :: z + optional :: z +end subroutine sub2a + +! VALID since TR29113 +subroutine sub2b(z) bind(C) + use iso_c_binding + optional :: z + integer(c_int) :: z +end subroutine sub2b + +! Invalid +subroutine sub3(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + integer(c_int), value, optional :: z +end subroutine sub3 + +! Invalid +subroutine sub3a(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + integer(c_int) :: z + optional :: z + value :: z +end subroutine sub3a + +! Invalid +subroutine sub3b(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + optional :: z + value :: z + integer(c_int) :: z +end subroutine sub3b + +! Invalid +subroutine sub3c(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + value :: z + integer(c_int) :: z + optional :: z +end subroutine sub3c diff --git a/gcc/testsuite/gfortran.dg/bind_c_usage_23.f90 b/gcc/testsuite/gfortran.dg/bind_c_usage_23.f90 new file mode 100644 index 00000000000..374f8129136 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_usage_23.f90 @@ -0,0 +1,64 @@ +! { dg-do compile } +! { dg-options "-std=f2008" } +! +! PR fortran/48858 +! PR fortran/48820 +! +! OPTIONAL + BIND(C) is allowed since TR 29113 +! + +! VALID +subroutine sub(z) bind(C) + use iso_c_binding + integer(c_int), value :: z +end subroutine sub + +! VALID since TR29113 +subroutine sub2(z) bind(C) ! { dg-error "with OPTIONAL attribute in procedure" } + use iso_c_binding + integer(c_int), optional :: z +end subroutine sub2 + +! VALID since TR29113 +subroutine sub2a(z) bind(C) ! { dg-error "with OPTIONAL attribute in procedure" } + use iso_c_binding + integer(c_int) :: z + optional :: z +end subroutine sub2a + +! VALID since TR29113 +subroutine sub2b(z) bind(C) ! { dg-error "with OPTIONAL attribute in procedure" } + use iso_c_binding + optional :: z + integer(c_int) :: z +end subroutine sub2b + +! Invalid +subroutine sub3(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + integer(c_int), value, optional :: z +end subroutine sub3 + +! Invalid +subroutine sub3a(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + integer(c_int) :: z + optional :: z + value :: z +end subroutine sub3a + +! Invalid +subroutine sub3b(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + optional :: z + value :: z + integer(c_int) :: z +end subroutine sub3b + +! Invalid +subroutine sub3c(z) bind(C) ! { dg-error "cannot have both the OPTIONAL and the VALUE attribute" } + use iso_c_binding + value :: z + integer(c_int) :: z + optional :: z +end subroutine sub3c