The attach patch allows for pointer initialization in a DATA statement per F2018. Yes, it's weird that a data-constant-object is not a named parameter. The 'data-constant-object' is required to have the SAVE and TARGET attribute.
Built and regression tested on x86_64-*-freebsd. OK to commit? PS: I'm sure Gerhard can break this. 2018-05-24 Steven G. Kargl <ka...@gcc.gnu.org> * decl.c (match_data_constant): Fortran 2018 allows pointer initialization in a data statement. 2018-05-24 Steven G. Kargl <ka...@gcc.gnu.org> * gfortran.dg/data_stmt_pointer.f90: new test. -- Steve
Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 260703) +++ gcc/fortran/decl.c (working copy) @@ -387,7 +387,20 @@ match_data_constant (gfc_expr **result) return m; } else if (m == MATCH_YES) - gfc_free_expr (*result); + { + /* F2018:R845 data-stmt-constant is initial-data-target. + A data-stmt-constant shall be ... initial-data-target if and + only if the corresponding data-stmt-object has the POINTER + attribute. ... If data-stmt-constant is initial-data-target + the corresponding data statement object shall be + data-pointer-initialization compatible (7.5.4.6) with the initial + data target; the data statement object is initially associated + with the target. */ + if ((*result)->symtree->n.sym->attr.save + && (*result)->symtree->n.sym->attr.target) + return m; + gfc_free_expr (*result); + } gfc_current_locus = old_loc; Index: gcc/testsuite/data_stmt_pointer.f90 =================================================================== --- gcc/testsuite/data_stmt_pointer.f90 (nonexistent) +++ gcc/testsuite/data_stmt_pointer.f90 (working copy) @@ -0,0 +1,19 @@ +! { dg-do run } +program foo + real, pointer :: p + real, save, target :: x = 42 + data p / x / + if (p /= 42) stop 1 + call bar +end program foo + +subroutine bar + type bah + integer, pointer :: p + end type bah + type(bah) a + integer, save, target :: i = 42 + data a%p / i / + if (a%p /= 42) stop 2 +end subroutine +