1 ! RUN: %python %S/test_errors.py %s %flang_fc1
3 ! Tests for defined input/output. See 12.6.4.8 and 15.4.3.2, and C777
8 procedure
, nopass
:: tbp
=>formattedReadProc
!Error, NOPASS not allowed
9 !ERROR: Defined input/output procedure 'tbp' may not have NOPASS attribute
10 generic
:: read(formatted
) => tbp
14 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
15 class(t
), intent(inout
) :: dtv
16 integer, intent(in
) :: unit
17 character(len
=*), intent(in
) :: iotype
18 integer, intent(in
) :: vlist(:)
19 integer, intent(out
) :: iostat
20 character(len
=*), intent(inout
) :: iomsg
31 procedure
, pass
:: tbp
=>formattedReadProc
32 !ERROR: Defined input/output procedure 'formattedreadproc' must have 6 dummy arguments rather than 5
33 generic
:: read(formatted
) => tbp
37 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
)
38 class(t
), intent(inout
) :: dtv
39 integer, intent(in
) :: unit
40 character(len
=*), intent(in
) :: iotype
41 integer, intent(in
) :: vlist(:)
42 integer, intent(out
) :: iostat
53 procedure
, pass
:: tbp
=>unformattedReadProc
54 !ERROR: Defined input/output procedure 'unformattedreadproc' must have 4 dummy arguments rather than 5
55 generic
:: read(unformatted
) => tbp
60 subroutine unformattedReadProc(dtv
, unit
, iostat
, iomsg
, iotype
)
61 class(t
), intent(inout
) :: dtv
62 integer, intent(in
) :: unit
63 integer, intent(out
) :: iostat
64 character(len
=*), intent(inout
) :: iomsg
65 integer, intent(out
) :: iotype
76 procedure
, pass
:: tbp
=>formattedReadProc
77 generic
:: read(formatted
) => tbp
81 !ERROR: Dummy argument 0 of 'formattedreadproc' must be a data object
82 !ERROR: Cannot use an alternate return as the passed-object dummy argument
83 subroutine formattedReadProc(*, unit
, iotype
, vlist
, iostat
, iomsg
)
84 !ERROR: Dummy argument 'unit' must be a data object
85 !ERROR: A dummy procedure without the POINTER attribute may not have an INTENT attribute
86 procedure(sin
), intent(in
) :: unit
87 character(len
=*), intent(in
) :: iotype
88 integer, intent(in
) :: vlist(:)
89 integer, intent(out
) :: iostat
90 character(len
=*), intent(inout
) :: iomsg
101 !ERROR: Passed-object dummy argument 'dtv' of procedure 'tbp' must be of type 't' but is 'INTEGER(4)'
102 procedure
, pass
:: tbp
=>formattedReadProc
103 generic
:: read(formatted
) => tbp
107 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
108 !ERROR: Dummy argument 'dtv' of a defined input/output procedure must have a derived type
109 integer, intent(inout
) :: dtv
! error, must be of type t
110 integer, intent(in
) :: unit
111 character(len
=*), intent(in
) :: iotype
112 integer, intent(in
) :: vlist(:)
113 integer, intent(out
) :: iostat
114 character(len
=*), intent(inout
) :: iomsg
122 interface read(formatted
)
123 procedure
:: formattedReadProc
127 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
128 !ERROR: Dummy argument 'dtv' of a defined input/output procedure must have a derived type
129 integer, intent(inout
) :: dtv
130 integer, intent(in
) :: unit
131 character(len
=*), intent(in
) :: iotype
! error, must be deferred
132 integer, intent(in
) :: vlist(:)
133 integer, intent(out
) :: iostat
134 character(len
=*), intent(inout
) :: iomsg
142 procedure
, pass
:: tbp
=>formattedReadProc
143 generic
:: read(formatted
) => tbp
147 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
148 !ERROR: Dummy argument 'dtv' of a defined input/output procedure must have intent 'INTENT(INOUT)'
149 class(t
), intent(in
) :: dtv
! Error, must be intent(inout)
150 integer, intent(in
) :: unit
151 character(len
=*), intent(in
) :: iotype
152 integer, intent(in
) :: vlist(:)
153 integer, intent(out
) :: iostat
154 character(len
=*), intent(inout
) :: iomsg
165 procedure
, pass
:: tbp
=>formattedWriteProc
166 generic
:: write(formatted
) => tbp
170 subroutine formattedWriteProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
171 !ERROR: Dummy argument 'dtv' of a defined input/output procedure must have intent 'INTENT(IN)'
172 class(t
), intent(inout
) :: dtv
! Error, must be intent(inout)
173 integer, intent(in
) :: unit
174 character(len
=*), intent(in
) :: iotype
175 integer, intent(in
) :: vlist(:)
176 integer, intent(out
) :: iostat
177 character(len
=*), intent(inout
) :: iomsg
188 procedure
, pass
:: tbp
=>formattedReadProc
189 generic
:: read(formatted
) => tbp
193 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
194 class(t
), intent(inout
) :: dtv
! Error, can't have attributes
195 !ERROR: Dummy argument 'unit' of a defined input/output procedure may not have any attributes
196 integer, pointer, intent(in
) :: unit
197 character(len
=*), intent(in
) :: iotype
198 integer, intent(in
) :: vlist(:)
199 integer, intent(out
) :: iostat
200 character(len
=*), intent(inout
) :: iomsg
211 procedure
, pass
:: tbp
=>formattedReadProc
212 generic
:: read(formatted
) => tbp
216 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
217 class(t
), intent(inout
) :: dtv
218 !ERROR: Dummy argument 'unit' of a defined input/output procedure must be an INTEGER of default KIND
219 real, intent(in
) :: unit
! Error, must be an integer
220 character(len
=*), intent(in
) :: iotype
221 integer, intent(in
) :: vlist(:)
222 integer, intent(out
) :: iostat
223 character(len
=*), intent(inout
) :: iomsg
234 procedure
, pass
:: tbp
=>formattedReadProc
235 generic
:: read(formatted
) => tbp
239 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
240 class(t
), intent(inout
) :: dtv
241 !ERROR: Dummy argument 'unit' of a defined input/output procedure must be an INTEGER of default KIND
242 integer(8), intent(in
) :: unit
! Error, must be default KIND
243 character(len
=*), intent(in
) :: iotype
244 integer, intent(in
) :: vlist(:)
245 integer, intent(out
) :: iostat
246 character(len
=*), intent(inout
) :: iomsg
257 procedure
, pass
:: tbp
=>formattedReadProc
258 generic
:: read(formatted
) => tbp
262 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
263 class(t
), intent(inout
) :: dtv
264 !ERROR: Dummy argument 'unit' of a defined input/output procedure must be a scalar
265 integer, dimension(22), intent(in
) :: unit
! Error, must be a scalar
266 character(len
=*), intent(in
) :: iotype
267 integer, intent(in
) :: vlist(:)
268 integer, intent(out
) :: iostat
269 character(len
=*), intent(inout
) :: iomsg
280 procedure
, pass
:: tbp
=>formattedReadProc
281 generic
:: read(formatted
) => tbp
285 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
286 class(t
), intent(inout
) :: dtv
287 !ERROR: Dummy argument 'unit' of a defined input/output procedure must have intent 'INTENT(IN)'
288 integer, intent(out
) :: unit
!Error, must be intent(in)
289 character(len
=*), intent(in
) :: iotype
290 integer, intent(in
) :: vlist(:)
291 integer, intent(out
) :: iostat
292 character(len
=*), intent(inout
) :: iomsg
303 procedure
, pass
:: tbp
=>formattedReadProc
304 generic
:: read(formatted
) => tbp
308 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
309 class(t
), intent(inout
) :: dtv
310 !ERROR: Dummy argument 'unit' of a defined input/output procedure must have intent 'INTENT(IN)'
311 integer :: unit
!Error, must be INTENT(IN)
312 character(len
=*), intent(in
) :: iotype
313 integer, intent(in
) :: vlist(:)
314 integer, intent(out
) :: iostat
315 character(len
=*), intent(inout
) :: iomsg
326 procedure
, pass
:: tbp
=>formattedReadProc
327 generic
:: read(formatted
) => tbp
331 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
332 class(t
), intent(inout
) :: dtv
333 integer, intent(in
) :: unit
334 !ERROR: Dummy argument 'iotype' of a defined input/output procedure must be assumed-length CHARACTER
335 character(len
=5), intent(in
) :: iotype
! Error, must be assumed length
336 integer, intent(in
) :: vlist(:)
337 integer, intent(out
) :: iostat
338 character(len
=*), intent(inout
) :: iomsg
349 procedure
, pass
:: tbp
=>formattedReadProc
350 generic
:: read(formatted
) => tbp
354 subroutine formattedReadProc(dtv
, unit
, iotype
, vlist
, iostat
, iomsg
)
355 class(t
), intent(inout
) :: dtv
356 integer, intent(in
) :: unit
357 character(len
=*), intent(in
) :: iotype
358 !ERROR: Dummy argument 'vlist' of a defined input/output procedure must be deferred shape
359 integer, intent(in
) :: vlist(5)
360 integer, intent(out
) :: iostat
361 character(len
=*), intent(inout
) :: iomsg
369 ! Test the same defined input/output procedure specified as a generic
373 procedure
:: formattedReadProc
376 interface read(formatted
)
377 module procedure formattedReadProc
381 subroutine formattedReadProc(dtv
,unit
,iotype
,v_list
,iostat
,iomsg
)
382 class(t
),intent(inout
) :: dtv
383 integer,intent(in
) :: unit
384 character(*),intent(in
) :: iotype
385 integer,intent(in
) :: v_list(:)
386 integer,intent(out
) :: iostat
387 character(*),intent(inout
) :: iomsg
388 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
394 ! Test the same defined input/output procedure specified as a type-bound
395 ! procedure and as a generic
399 procedure
:: formattedReadProc
400 generic
:: read(formatted
) => formattedReadProc
402 interface read(formatted
)
403 module procedure formattedReadProc
406 subroutine formattedReadProc(dtv
,unit
,iotype
,v_list
,iostat
,iomsg
)
407 class(t
),intent(inout
) :: dtv
408 integer,intent(in
) :: unit
409 character(*),intent(in
) :: iotype
410 integer,intent(in
) :: v_list(:)
411 integer,intent(out
) :: iostat
412 character(*),intent(inout
) :: iomsg
413 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
419 ! Test two different defined input/output procedures specified as a
420 ! type-bound procedure and as a generic for the same derived type
424 procedure
:: unformattedReadProc1
425 generic
:: read(unformatted
) => unformattedReadProc1
427 interface read(unformatted
)
428 module procedure unformattedReadProc
431 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
432 class(t
),intent(inout
) :: dtv
433 integer,intent(in
) :: unit
434 integer,intent(out
) :: iostat
435 character(*),intent(inout
) :: iomsg
436 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
438 !ERROR: Derived type 't' already has defined input/output procedure 'read(unformatted)'
439 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
440 class(t
),intent(inout
) :: dtv
441 integer,intent(in
) :: unit
442 integer,intent(out
) :: iostat
443 character(*),intent(inout
) :: iomsg
444 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
449 ! Test read and write defined input/output procedures specified as a
450 ! type-bound procedure and as a generic for the same derived type
454 procedure
:: unformattedReadProc
455 generic
:: read(unformatted
) => unformattedReadProc
457 interface read(unformatted
)
458 module procedure unformattedReadProc
460 interface write(unformatted
)
461 module procedure unformattedWriteProc
464 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
465 class(t
),intent(inout
) :: dtv
466 integer,intent(in
) :: unit
467 integer,intent(out
) :: iostat
468 character(*),intent(inout
) :: iomsg
469 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
471 subroutine unformattedWriteProc(dtv
,unit
,iostat
,iomsg
)
472 class(t
),intent(in
) :: dtv
473 integer,intent(in
) :: unit
474 integer,intent(out
) :: iostat
475 character(*),intent(inout
) :: iomsg
476 write(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
481 ! Test read and write defined input/output procedures specified as a
482 ! type-bound procedure and as a generic for the same derived type with a
483 ! KIND type parameter where they both have the same value
485 integer, kind
:: typeParam
= 4
488 procedure
:: unformattedReadProc
489 generic
:: read(unformatted
) => unformattedReadProc
491 interface read(unformatted
)
492 module procedure unformattedReadProc1
495 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
496 class(t
),intent(inout
) :: dtv
497 integer,intent(in
) :: unit
498 integer,intent(out
) :: iostat
499 character(*),intent(inout
) :: iomsg
500 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
502 !ERROR: Derived type 't' already has defined input/output procedure 'read(unformatted)'
503 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
504 class(t(4)),intent(inout
) :: dtv
505 integer,intent(in
) :: unit
506 integer,intent(out
) :: iostat
507 character(*),intent(inout
) :: iomsg
508 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
513 ! Test read and write defined input/output procedures specified as a
514 ! type-bound procedure and as a generic for the same derived type with a
515 ! KIND type parameter where they have different values
517 integer, kind
:: typeParam
= 4
520 procedure
:: unformattedReadProc
521 generic
:: read(unformatted
) => unformattedReadProc
523 interface read(unformatted
)
524 module procedure unformattedReadProc1
527 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
528 class(t
),intent(inout
) :: dtv
529 integer,intent(in
) :: unit
530 integer,intent(out
) :: iostat
531 character(*),intent(inout
) :: iomsg
532 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
534 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
535 class(t(3)),intent(inout
) :: dtv
536 integer,intent(in
) :: unit
537 integer,intent(out
) :: iostat
538 character(*),intent(inout
) :: iomsg
539 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
545 ! Test read and write defined input/output procedures specified as a
546 ! type-bound procedure and as a generic for the same derived type with a
547 ! LEN type parameter where they have different values
548 integer, len
:: typeParam
= 4
551 procedure
:: unformattedReadProc
552 generic
:: read(unformatted
) => unformattedReadProc
554 interface read(unformatted
)
555 module procedure unformattedReadProc1
558 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
559 class(t(*)),intent(inout
) :: dtv
560 integer,intent(in
) :: unit
561 integer,intent(out
) :: iostat
562 character(*),intent(inout
) :: iomsg
563 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
565 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
566 class(t(3)),intent(inout
) :: dtv
567 integer,intent(in
) :: unit
568 integer,intent(out
) :: iostat
569 character(*),intent(inout
) :: iomsg
570 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
575 ! Test read and write defined input/output procedures specified as a
576 ! type-bound procedure and as a generic for the same derived type with a
577 ! LEN type parameter where they have the same value
579 integer, len
:: typeParam
= 4
582 procedure
:: unformattedReadProc
583 generic
:: read(unformatted
) => unformattedReadProc
585 interface read(unformatted
)
586 module procedure unformattedReadProc1
589 subroutine unformattedReadProc(dtv
,unit
,iostat
,iomsg
)
590 class(t(*)),intent(inout
) :: dtv
591 integer,intent(in
) :: unit
592 integer,intent(out
) :: iostat
593 character(*),intent(inout
) :: iomsg
594 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
596 !ERROR: Derived type 't' already has defined input/output procedure 'read(unformatted)'
597 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
598 class(t(*)),intent(inout
) :: dtv
599 integer,intent(in
) :: unit
600 integer,intent(out
) :: iostat
601 character(*),intent(inout
) :: iomsg
602 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
607 ! Test against false error when two defined I/O procedures exist
608 ! for the same type but are not both visible in the same scope.
612 interface read(unformatted
)
613 module procedure unformattedReadProc1
616 subroutine unformattedReadProc1(dtv
,unit
,iostat
,iomsg
)
617 class(t
),intent(inout
) :: dtv
618 integer,intent(in
) :: unit
619 integer,intent(out
) :: iostat
620 character(*),intent(inout
) :: iomsg
621 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c
626 interface read(unformatted
)
627 procedure unformattedReadProc2
630 subroutine unformattedReadProc2(dtv
,unit
,iostat
,iomsg
)
631 class(t
),intent(inout
) :: dtv
632 integer,intent(in
) :: unit
633 integer,intent(out
) :: iostat
634 character(*),intent(inout
) :: iomsg
635 read(unit
,iotype
,iostat
=iostat
,iomsg
=iomsg
) dtv
%c