| 1 |
! PR 101320 |
| 2 |
! { dg-do compile } |
| 3 |
! |
| 4 |
! TS 29113 |
| 5 |
! C516 The ALLOCATABLE or POINTER attribute shall not be specified for |
| 6 |
! a default-initialized dummy argument of a procedure that has a |
| 7 |
! proc-language-binding-spec. |
| 8 |
! |
| 9 |
! This file contains code that is expected to produce errors. |
| 10 |
|
| 11 |
module m1 |
| 12 |
|
| 13 |
type, bind(c) :: t1 |
| 14 |
integer :: a |
| 15 |
integer :: b |
| 16 |
end type |
| 17 |
|
| 18 |
|
| 19 |
type, bind(c) :: t2 |
| 20 |
integer :: a = 0 |
| 21 |
integer :: b = -1 |
| 22 |
end type |
| 23 |
|
| 24 |
end module |
| 25 |
|
| 26 |
module m2 |
| 27 |
|
| 28 |
interface |
| 29 |
|
| 30 |
! First test versions with optional attributes on the argument. |
| 31 |
! TS29113 removed the constraint disallowing optional arguments |
| 32 |
! that previously used to be in C516. |
| 33 |
|
| 34 |
! good, no default initialization, no pointer/allocatable attribute |
| 35 |
subroutine s1a (x) bind (c) |
| 36 |
use m1 |
| 37 |
type(t1), optional :: x |
| 38 |
end subroutine |
| 39 |
|
| 40 |
! good, no default initialization |
| 41 |
subroutine s1b (x) bind (c) |
| 42 |
use m1 |
| 43 |
type(t1), allocatable, optional :: x |
| 44 |
end subroutine |
| 45 |
|
| 46 |
! good, no default initialization |
| 47 |
subroutine s1c (x) bind (c) |
| 48 |
use m1 |
| 49 |
type(t1), pointer, optional :: x |
| 50 |
end subroutine |
| 51 |
|
| 52 |
! good, default initialization but no pointer/allocatable attribute |
| 53 |
subroutine s2a (x) bind (c) |
| 54 |
use m1 |
| 55 |
type(t2), optional :: x |
| 56 |
end subroutine |
| 57 |
|
| 58 |
! bad, default initialization + allocatable |
| 59 |
subroutine s2b (x) bind (c) ! { dg-error "BIND\\(C\\)" } |
| 60 |
use m1 |
| 61 |
type(t2), allocatable, optional :: x |
| 62 |
end subroutine |
| 63 |
|
| 64 |
! bad, default initialization + pointer |
| 65 |
subroutine s2c (x) bind (c) ! { dg-error "BIND\\(C\\)" } |
| 66 |
use m1 |
| 67 |
type(t2), pointer, optional :: x |
| 68 |
end subroutine |
| 69 |
|
| 70 |
! Now do all the same tests without the optional attribute. |
| 71 |
|
| 72 |
! good, no default initialization, no pointer/allocatable attribute |
| 73 |
subroutine s3a (x) bind (c) |
| 74 |
use m1 |
| 75 |
type(t1) :: x |
| 76 |
end subroutine |
| 77 |
|
| 78 |
! good, no default initialization |
| 79 |
subroutine s3b (x) bind (c) |
| 80 |
use m1 |
| 81 |
type(t1), allocatable :: x |
| 82 |
end subroutine |
| 83 |
|
| 84 |
! good, no default initialization |
| 85 |
subroutine s3c (x) bind (c) |
| 86 |
use m1 |
| 87 |
type(t1), pointer :: x |
| 88 |
end subroutine |
| 89 |
|
| 90 |
! good, default initialization but no pointer/allocatable attribute |
| 91 |
subroutine s4a (x) bind (c) |
| 92 |
use m1 |
| 93 |
type(t2) :: x |
| 94 |
end subroutine |
| 95 |
|
| 96 |
! bad, default initialization + allocatable |
| 97 |
subroutine s4b (x) bind (c) ! { dg-error "BIND\\(C\\)" } |
| 98 |
use m1 |
| 99 |
type(t2), allocatable :: x |
| 100 |
end subroutine |
| 101 |
|
| 102 |
! bad, default initialization + pointer |
| 103 |
subroutine s4c (x) bind (c) ! { dg-error "BIND\\(C\\)" } |
| 104 |
use m1 |
| 105 |
type(t2), pointer :: x |
| 106 |
end subroutine |
| 107 |
|
| 108 |
end interface |
| 109 |
end module |