Bug 89344 - uncaught programmer error: polymorphic variable is INTENT(IN) but assigned to without error
Summary: uncaught programmer error: polymorphic variable is INTENT(IN) but assigned t...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.3.0
: P4 normal
Target Milestone: ---
Assignee: kargl
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2019-02-13 19:23 UTC by urbanjost
Modified: 2019-02-19 03:58 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-02-13 00:00:00


Attachments
Patch that detects and issues an error. (465 bytes, patch)
2019-02-13 22:03 UTC, kargl
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description urbanjost 2019-02-13 19:23:21 UTC

    
Comment 1 urbanjost 2019-02-13 19:30:17 UTC
program demo_setval
   call setval(value)
   write(*,*)'VALUE=',value
CONTAINS
   subroutine setval(value)
      class(*),intent(in)          :: value
      select type(value)
       type is (integer);          value=10
       type is (real);             value=10.20
      end select
   end subroutine setval
end program demo_setval
! expect to get something like
!    Error: Dummy argument 'value' with INTENT(IN) in variable definition context (assignment) at (1)
! but do not even though VALUE is INTENT(IN) and changed the value


There is a programmer error in the example program. The variable VALUE has been
declared to be INTENT(IN) but the routine assigns a value to the variable. This
should be caught at compile time.
Comment 2 kargl 2019-02-13 21:59:40 UTC
My version of gfortran gives

% gfcx -c a.f90
a.f90:8:35:

    8 |        type is (integer);          value=10
      |                                   1
Error: Dummy argument 'value' with INTENT(IN) in variable definition context (assignment) at (1)
a.f90:9:35:

    9 |        type is (real);             value=10.20
      |                                   1
Error: Dummy argument 'value' with INTENT(IN) in variable definition context (assignment) at (1)
Comment 3 kargl 2019-02-13 22:03:04 UTC
Created attachment 45708 [details]
Patch that detects and issues an error.

Patch that detects and issues an error.  Trunk is in stage 4, so the patch will likely get committed after 9.1 is released.
Comment 4 Dominique d'Humieres 2019-02-13 23:23:31 UTC
Confirmed from at least 4.8 up to trunk (9.0).
Comment 5 urbanjost 2019-02-19 03:58:45 UTC
That was fast. Thanks!