Bug 42188 - [OOP] F03:C612. The leftmost part-name shall be the name of a data object.
Summary: [OOP] F03:C612. The leftmost part-name shall be the name of a data object.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 7.0
Assignee: janus
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2009-11-26 21:01 UTC by janus
Modified: 2016-12-03 18:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-09-10 21:38:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-11-26 21:01:34 UTC
Follow-up to PR42048. Consider the following code:

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
   call new_field()%mesh%new_grid()
   i = new_field()%mesh%new_int()
 end subroutine

end module


which is currently rejected with

test.f90:41.3:

   g = new_field()%mesh
   1
Error: Unclassifiable statement at (1)
test.f90:42.19:

   call new_field()%mesh%new_grid()
                   1
Error: Syntax error in CALL statement at (1)
test.f90:43.3:

   i = new_field()%mesh%new_int()
   1
Error: Unclassifiable statement at (1)


Rejecting it is fine, I think, but the error messages should be improved. ifort says

error #6837: The leftmost part-ref in a data-ref can not be a function
reference.   


The relevant parts from the standard are:

R612 data-ref is part-ref [ % part-ref ] ...
R613 part-ref is part-name [ ( section-subscript-list ) ]

C612 (R612) The leftmost part-name shall be the name of a data object.

2.4.3.1 Data object
A data object (often abbreviated to object) is a constant (4.1.2), a variable
(6), or a subobject of a constant.
Comment 1 janus 2016-12-03 18:38:29 UTC
Author: janus
Date: Sat Dec  3 18:37:57 2016
New Revision: 243223

URL: https://gcc.gnu.org/viewcvs?rev=243223&root=gcc&view=rev
Log:
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.

Added:
    trunk/gcc/testsuite/gfortran.dg/derived_result_2.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/primary.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 janus 2016-12-03 18:39:56 UTC
Fixed on 7-trunk with r243223. Closing.