From: Steven G. Kargl Date: Sun, 4 Sep 2016 20:00:48 +0000 (+0000) Subject: re PR fortran/77391 (gfortran allows CHARACTER(LEN=:),PARAMETER:: STRING='constant... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f2bc4e4800590aa59b0ac126676786dd4ce77867;p=gcc.git re PR fortran/77391 (gfortran allows CHARACTER(LEN=:),PARAMETER:: STRING='constant' buts does not report it as an extension) 2016-09-04 Steven G. Kargl PR fortran/77391 * resolve.c (deferred_requirements): New function to check F2008:C402. (resolve_fl_variable,resolve_fl_parameter): Use it. 2016-09-04 Steven G. Kargl PR fortran/77391 * gfortran.dg/pr77391.f90: New test. From-SVN: r239982 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0b452f4664e..8e525dc5fd6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-09-04 Steven G. Kargl + + PR fortran/77391 + * resolve.c (deferred_requirements): New function to check F2008:C402. + (resolve_fl_variable,resolve_fl_parameter): Use it. + 2016-09-04 Steven G. Kargl PR fortran/77460 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 39c1330c455..f8ba00bab82 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11488,6 +11488,27 @@ resolve_fl_variable_derived (gfc_symbol *sym, int no_init_flag) } +/* F2008, C402 (R401): A colon shall not be used as a type-param-value + except in the declaration of an entity or component that has the POINTER + or ALLOCATABLE attribute. */ + +static bool +deferred_requirements (gfc_symbol *sym) +{ + if (sym->ts.deferred + && !(sym->attr.pointer + || sym->attr.allocatable + || sym->attr.omp_udr_artificial_var)) + { + gfc_error ("Entity %qs at %L has a deferred type parameter and " + "requires either the POINTER or ALLOCATABLE attribute", + sym->name, &sym->declared_at); + return false; + } + return true; +} + + /* Resolve symbols with flavor variable. */ static bool @@ -11527,17 +11548,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) } /* Constraints on deferred type parameter. */ - if (sym->ts.deferred - && !(sym->attr.pointer - || sym->attr.allocatable - || sym->attr.omp_udr_artificial_var)) - { - gfc_error ("Entity %qs at %L has a deferred type parameter and " - "requires either the pointer or allocatable attribute", - sym->name, &sym->declared_at); - specification_expr = saved_specification_expr; - return false; - } + if (!deferred_requirements (sym)) + return false; if (sym->ts.type == BT_CHARACTER) { @@ -13682,6 +13694,10 @@ resolve_fl_parameter (gfc_symbol *sym) return false; } + /* Constraints on deferred type parameter. */ + if (!deferred_requirements (sym)) + return false; + /* Make sure a parameter that has been implicitly typed still matches the implicit type, since PARAMETER statements can precede IMPLICIT statements. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6f5c7878bd6..79ef275a01d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-04 Steven G. Kargl + + PR fortran/77391 + * gfortran.dg/pr77391.f90: New test. + 2016-09-04 Steven G. Kargl PR fortran/77460 diff --git a/gcc/testsuite/gfortran.dg/pr77391.f90 b/gcc/testsuite/gfortran.dg/pr77391.f90 new file mode 100644 index 00000000000..b3a455aa719 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr77391.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +program picky +character(len=:), parameter :: a="whoops" ! { dg-error "POINTER or ALLOCATABLE" } +character(len=:) :: b="whoops" ! { dg-error "POINTER or ALLOCATABLE" } +character(len=:) :: good +pointer good +end program picky