re PR fortran/42188 ([OOP] F03:C612. The leftmost part-name shall be the name of...
authorJanus Weil <janus@gcc.gnu.org>
Sat, 3 Dec 2016 18:37:57 +0000 (19:37 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Sat, 3 Dec 2016 18:37:57 +0000 (19:37 +0100)
2016-12-03  Janus Weil  <janus@gcc.gnu.org>

PR fortran/42188
* primary.c (gfc_match_rvalue): Add a new check that gives better error
messages.

2016-12-03  Janus Weil  <janus@gcc.gnu.org>

PR fortran/42188
* gfortran.dg/derived_result_2.f90.f90: New test case.

From-SVN: r243223

gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/derived_result_2.f90 [new file with mode: 0644]

index 7a007c3025172db2c35d9cdfb1f79e0a212680f2..eaae6961dfe8144f7fcee497873e259d1f5a1e98 100644 (file)
@@ -1,3 +1,9 @@
+2016-12-03  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/42188
+       * primary.c (gfc_match_rvalue): Add a new check that gives better error
+       messages.
+
 2016-12-03  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/58175
index eb2d780943202cf19302268cd32dafcf1406cb8a..2cdc9a4a23ca103007d46f26c6e57391e18424ea 100644 (file)
@@ -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;
 
index 39a5c595a23619a569870c79abdee69fadb4a8d0..0d95973ef8a98e9db82b5f67e6866290e497f702 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-03  Janus Weil  <janus@gcc.gnu.org>
+
+       PR fortran/42188
+       * gfortran.dg/derived_result_2.f90.f90: New test case.
+
 2016-12-03  Janus Weil  <janus@gcc.gnu.org>
 
        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 (file)
index 0000000..51f5b86
--- /dev/null
@@ -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 <janus@gcc.gnu.org>
+
+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