From 20fee4a901c0cf097df1f1ba00e226f1eb8e973c Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Sat, 3 Dec 2016 19:37:57 +0100 Subject: [PATCH] re PR fortran/42188 ([OOP] F03:C612. The leftmost part-name shall be the name of a data object.) 2016-12-03 Janus Weil PR fortran/42188 * primary.c (gfc_match_rvalue): Add a new check that gives better error messages. 2016-12-03 Janus Weil PR fortran/42188 * gfortran.dg/derived_result_2.f90.f90: New test case. From-SVN: r243223 --- gcc/fortran/ChangeLog | 6 +++ gcc/fortran/primary.c | 9 ++++ gcc/testsuite/ChangeLog | 5 +++ .../gfortran.dg/derived_result_2.f90 | 45 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/derived_result_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7a007c30251..eaae6961dfe 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-12-03 Janus Weil + + PR fortran/42188 + * primary.c (gfc_match_rvalue): Add a new check that gives better error + messages. + 2016-12-03 Janus Weil PR fortran/58175 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index eb2d7809432..2cdc9a4a23c 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -3298,6 +3298,15 @@ gfc_match_rvalue (gfc_expr **result) if (sym->result == NULL) sym->result = sym; + gfc_gobble_whitespace (); + /* F08:C612. */ + if (gfc_peek_ascii_char() == '%') + { + gfc_error ("The leftmost part-ref in a data-ref can not be a " + "function reference at %C"); + m = MATCH_ERROR; + } + m = MATCH_YES; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 39a5c595a23..0d95973ef8a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-03 Janus Weil + + PR fortran/42188 + * gfortran.dg/derived_result_2.f90.f90: New test case. + 2016-12-03 Janus Weil PR fortran/58175 diff --git a/gcc/testsuite/gfortran.dg/derived_result_2.f90 b/gcc/testsuite/gfortran.dg/derived_result_2.f90 new file mode 100644 index 00000000000..51f5b863494 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/derived_result_2.f90 @@ -0,0 +1,45 @@ +! { dg-do compile } +! +! PR 42188: [OOP] F03:C612. The leftmost part-name shall be the name of a data object +! +! Contributed by Janus Weil + +module grid_module + implicit none + type grid + contains + procedure :: new_grid + procedure :: new_int + end type +contains + subroutine new_grid(this) + class(grid) :: this + end subroutine + integer function new_int(this) + class(grid) :: this + new_int = 42 + end function +end module + +module field_module + use grid_module + implicit none + + type field + type(grid) :: mesh + end type + +contains + + type(field) function new_field() + end function + + subroutine test + integer :: i + type(grid) :: g + g = new_field()%mesh ! { dg-error "can not be a function reference" } + call new_field()%mesh%new_grid() ! { dg-error "Syntax error" } + i = new_field() % mesh%new_int() ! { dg-error "can not be a function reference" } + end subroutine + +end module -- 2.30.2