xref: /llvm-project/flang/test/Semantics/call05.f90 (revision 33c27f28d1cd05fd0a739498105927c1fba04666)
1dc78329dSPeter Klausler! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
264ab3302SCarolineConcatto! Test 15.5.2.5 constraints and restrictions for POINTER & ALLOCATABLE
364ab3302SCarolineConcatto! arguments when both sides of the call have the same attributes.
464ab3302SCarolineConcatto
564ab3302SCarolineConcattomodule m
664ab3302SCarolineConcatto
764ab3302SCarolineConcatto  type :: t
864ab3302SCarolineConcatto  end type
964ab3302SCarolineConcatto  type, extends(t) :: t2
1064ab3302SCarolineConcatto  end type
1164ab3302SCarolineConcatto  type :: pdt(n)
1264ab3302SCarolineConcatto    integer, len :: n
1364ab3302SCarolineConcatto  end type
1464ab3302SCarolineConcatto
1564ab3302SCarolineConcatto  type(t), pointer :: mp(:), mpmat(:,:)
1664ab3302SCarolineConcatto  type(t), allocatable :: ma(:), mamat(:,:)
1764ab3302SCarolineConcatto  class(t), pointer :: pp(:)
1864ab3302SCarolineConcatto  class(t), allocatable :: pa(:)
1964ab3302SCarolineConcatto  class(t2), pointer :: pp2(:)
2064ab3302SCarolineConcatto  class(t2), allocatable :: pa2(:)
2164ab3302SCarolineConcatto  class(*), pointer :: up(:)
2264ab3302SCarolineConcatto  class(*), allocatable :: ua(:)
2341a964cfSPeter Klausler  !ERROR: An assumed (*) type parameter may be used only for a (non-statement function) dummy argument, associate name, character named constant, or external function result
2464ab3302SCarolineConcatto  type(pdt(*)), pointer :: amp(:)
2541a964cfSPeter Klausler  !ERROR: An assumed (*) type parameter may be used only for a (non-statement function) dummy argument, associate name, character named constant, or external function result
2664ab3302SCarolineConcatto  type(pdt(*)), allocatable :: ama(:)
2764ab3302SCarolineConcatto  type(pdt(:)), pointer :: dmp(:)
2864ab3302SCarolineConcatto  type(pdt(:)), allocatable :: dma(:)
2964ab3302SCarolineConcatto  type(pdt(1)), pointer :: nmp(:)
3064ab3302SCarolineConcatto  type(pdt(1)), allocatable :: nma(:)
3164ab3302SCarolineConcatto
3264ab3302SCarolineConcatto contains
3364ab3302SCarolineConcatto
3464ab3302SCarolineConcatto  subroutine smp(x)
3564ab3302SCarolineConcatto    type(t), pointer :: x(:)
3664ab3302SCarolineConcatto  end subroutine
3764ab3302SCarolineConcatto  subroutine sma(x)
3864ab3302SCarolineConcatto    type(t), allocatable :: x(:)
3964ab3302SCarolineConcatto  end subroutine
4064ab3302SCarolineConcatto  subroutine spp(x)
4164ab3302SCarolineConcatto    class(t), pointer :: x(:)
4264ab3302SCarolineConcatto  end subroutine
4364ab3302SCarolineConcatto  subroutine spa(x)
4464ab3302SCarolineConcatto    class(t), allocatable :: x(:)
4564ab3302SCarolineConcatto  end subroutine
4664ab3302SCarolineConcatto  subroutine sup(x)
4764ab3302SCarolineConcatto    class(*), pointer :: x(:)
4864ab3302SCarolineConcatto  end subroutine
4964ab3302SCarolineConcatto  subroutine sua(x)
5064ab3302SCarolineConcatto    class(*), allocatable :: x(:)
5164ab3302SCarolineConcatto  end subroutine
5264ab3302SCarolineConcatto  subroutine samp(x)
5364ab3302SCarolineConcatto    type(pdt(*)), pointer :: x(:)
5464ab3302SCarolineConcatto  end subroutine
5564ab3302SCarolineConcatto  subroutine sama(x)
5664ab3302SCarolineConcatto    type(pdt(*)), allocatable :: x(:)
5764ab3302SCarolineConcatto  end subroutine
5864ab3302SCarolineConcatto  subroutine sdmp(x)
5964ab3302SCarolineConcatto    type(pdt(:)), pointer :: x(:)
6064ab3302SCarolineConcatto  end subroutine
6164ab3302SCarolineConcatto  subroutine sdma(x)
6264ab3302SCarolineConcatto    type(pdt(:)), allocatable :: x(:)
6364ab3302SCarolineConcatto  end subroutine
6464ab3302SCarolineConcatto  subroutine snmp(x)
6564ab3302SCarolineConcatto    type(pdt(1)), pointer :: x(:)
6664ab3302SCarolineConcatto  end subroutine
6764ab3302SCarolineConcatto  subroutine snma(x)
6864ab3302SCarolineConcatto    type(pdt(1)), allocatable :: x(:)
6964ab3302SCarolineConcatto  end subroutine
7064ab3302SCarolineConcatto
7164ab3302SCarolineConcatto  subroutine test
7264ab3302SCarolineConcatto    call smp(mp) ! ok
7364ab3302SCarolineConcatto    call sma(ma) ! ok
7464ab3302SCarolineConcatto    call spp(pp) ! ok
7564ab3302SCarolineConcatto    call spa(pa) ! ok
76dc78329dSPeter Klausler    !PORTABILITY: If a POINTER or ALLOCATABLE actual argument is polymorphic, the corresponding dummy argument should also be so
7764ab3302SCarolineConcatto    call smp(pp)
78dc78329dSPeter Klausler    !PORTABILITY: If a POINTER or ALLOCATABLE actual argument is polymorphic, the corresponding dummy argument should also be so
7964ab3302SCarolineConcatto    call sma(pa)
8064ab3302SCarolineConcatto    !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is polymorphic, both must be so
8164ab3302SCarolineConcatto    call spp(mp)
8264ab3302SCarolineConcatto    !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is polymorphic, both must be so
8364ab3302SCarolineConcatto    call spa(ma)
8464ab3302SCarolineConcatto    !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is unlimited polymorphic, both must be so
8564ab3302SCarolineConcatto    call sup(pp)
8664ab3302SCarolineConcatto    !ERROR: If a POINTER or ALLOCATABLE dummy or actual argument is unlimited polymorphic, both must be so
8764ab3302SCarolineConcatto    call sua(pa)
88036701a1SPeter Klausler    !ERROR: Actual argument type 'CLASS(*)' is not compatible with dummy argument type 'CLASS(t)'
891fa9ef62SPeter Klausler    !ERROR: Pointer type must be unlimited polymorphic or non-extensible derived type when target is unlimited polymorphic
9064ab3302SCarolineConcatto    call spp(up)
91036701a1SPeter Klausler    !ERROR: Actual argument type 'CLASS(*)' is not compatible with dummy argument type 'CLASS(t)'
9264ab3302SCarolineConcatto    call spa(ua)
9337b2e2b0Speter klausler    !ERROR: POINTER or ALLOCATABLE dummy and actual arguments must have the same declared type and kind
9464ab3302SCarolineConcatto    call spp(pp2)
9537b2e2b0Speter klausler    !ERROR: POINTER or ALLOCATABLE dummy and actual arguments must have the same declared type and kind
9664ab3302SCarolineConcatto    call spa(pa2)
9764ab3302SCarolineConcatto    !ERROR: Rank of dummy argument is 1, but actual argument has rank 2
981fa9ef62SPeter Klausler    !ERROR: Pointer has rank 1 but target has rank 2
9964ab3302SCarolineConcatto    call smp(mpmat)
10064ab3302SCarolineConcatto    !ERROR: Rank of dummy argument is 1, but actual argument has rank 2
10164ab3302SCarolineConcatto    call sma(mamat)
10264ab3302SCarolineConcatto    call sdmp(dmp) ! ok
10364ab3302SCarolineConcatto    call sdma(dma) ! ok
10464ab3302SCarolineConcatto    call snmp(nmp) ! ok
10564ab3302SCarolineConcatto    call snma(nma) ! ok
10664ab3302SCarolineConcatto    call samp(nmp) ! ok
10764ab3302SCarolineConcatto    call sama(nma) ! ok
10864ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
10964ab3302SCarolineConcatto    call sdmp(nmp)
11064ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
11164ab3302SCarolineConcatto    call sdma(nma)
11264ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
11364ab3302SCarolineConcatto    call snmp(dmp)
11464ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
11564ab3302SCarolineConcatto    call snma(dma)
11664ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
11764ab3302SCarolineConcatto    call samp(dmp)
11864ab3302SCarolineConcatto    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
11964ab3302SCarolineConcatto    call sama(dma)
12064ab3302SCarolineConcatto  end subroutine
12164ab3302SCarolineConcatto
12264ab3302SCarolineConcattoend module
1237c158e3eSJean Perier
1247c158e3eSJean Periermodule m2
1257c158e3eSJean Perier
1267c158e3eSJean Perier  character(len=10), allocatable :: t1, t2, t3, t4
1277c158e3eSJean Perier  character(len=:), allocatable :: t5, t6, t7, t8(:)
1287c158e3eSJean Perier
1297c158e3eSJean Perier  character(len=10), pointer :: p1
1307c158e3eSJean Perier  character(len=:), pointer :: p2
1317c158e3eSJean Perier
1327c158e3eSJean Perier  integer, allocatable :: x(:)
1337c158e3eSJean Perier
1347c158e3eSJean Perier contains
1357c158e3eSJean Perier
1367c158e3eSJean Perier  subroutine sma(a)
1377c158e3eSJean Perier    character(len=:), allocatable, intent(in) :: a
1387c158e3eSJean Perier  end
1397c158e3eSJean Perier
1407c158e3eSJean Perier  subroutine sma2(a)
1417c158e3eSJean Perier    character(len=10), allocatable, intent(in) :: a
1427c158e3eSJean Perier  end
1437c158e3eSJean Perier
1447c158e3eSJean Perier  subroutine smp(p)
1457c158e3eSJean Perier    character(len=:), pointer, intent(in) :: p
1467c158e3eSJean Perier  end
1477c158e3eSJean Perier
1487c158e3eSJean Perier  subroutine smp2(p)
1497c158e3eSJean Perier    character(len=10), pointer, intent(in) :: p
1507c158e3eSJean Perier  end
1517c158e3eSJean Perier
1527c158e3eSJean Perier  subroutine smb(b)
1537c158e3eSJean Perier    integer, allocatable, intent(in) :: b(:)
1547c158e3eSJean Perier  end
1557c158e3eSJean Perier
1568c127074SjeanPerier  function return_deferred_length_ptr()
1578c127074SjeanPerier    character(len=:), pointer :: return_deferred_length_ptr
158*33c27f28SPeter Klausler    return_deferred_length_ptr => p2
1598c127074SjeanPerier  end function
1608c127074SjeanPerier
1618c127074SjeanPerier  function return_explicit_length_ptr(n)
1628c127074SjeanPerier    integer :: n
1638c127074SjeanPerier    character(len=n), pointer :: return_explicit_length_ptr
164*33c27f28SPeter Klausler    return_explicit_length_ptr => p2(1:n)
1658c127074SjeanPerier  end function
1668c127074SjeanPerier
1677c158e3eSJean Perier  subroutine test()
1687c158e3eSJean Perier
169fbdcb3ceSPeixinQiao    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
170fbdcb3ceSPeixinQiao    call sma(t1)
171fbdcb3ceSPeixinQiao
1727c158e3eSJean Perier    call sma2(t1) ! ok
1737c158e3eSJean Perier
174fbdcb3ceSPeixinQiao    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
175fbdcb3ceSPeixinQiao    call smp(p1)
176fbdcb3ceSPeixinQiao
1777c158e3eSJean Perier    call smp2(p1) ! ok
1787c158e3eSJean Perier
1798c127074SjeanPerier    call smp(return_deferred_length_ptr()) ! ok
1808c127074SjeanPerier
1818c127074SjeanPerier    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
1828c127074SjeanPerier    call smp2(return_deferred_length_ptr())
1838c127074SjeanPerier
1848c127074SjeanPerier    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
1858c127074SjeanPerier    call smp(return_explicit_length_ptr(10))
1868c127074SjeanPerier
1878c127074SjeanPerier    call smp2(return_explicit_length_ptr(10)) ! ok
1888c127074SjeanPerier
1897c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
1907c158e3eSJean Perier    call sma(t2(:))
1917c158e3eSJean Perier
1923602efa7SPeter Klausler    !ERROR: 't3' is not a callable procedure
1937c158e3eSJean Perier    call sma(t3(1))
1947c158e3eSJean Perier
1957c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
1967c158e3eSJean Perier    call sma(t4(1:2))
1977c158e3eSJean Perier
1987c158e3eSJean Perier    call sma(t5) ! ok
1997c158e3eSJean Perier
200fbdcb3ceSPeixinQiao    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
201fbdcb3ceSPeixinQiao    call sma2(t5)
202fbdcb3ceSPeixinQiao
2037c158e3eSJean Perier    call smp(p2) ! ok
2047c158e3eSJean Perier
205fbdcb3ceSPeixinQiao    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
206fbdcb3ceSPeixinQiao    call smp2(p2)
207fbdcb3ceSPeixinQiao
2087c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
2097c158e3eSJean Perier    call sma(t5(:))
2107c158e3eSJean Perier
2113602efa7SPeter Klausler    !ERROR: 't6' is not a callable procedure
2127c158e3eSJean Perier    call sma(t6(1))
2137c158e3eSJean Perier
2147c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
2157c158e3eSJean Perier    call sma(t7(1:2))
2167c158e3eSJean Perier
2177c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'a=' must be associated with an ALLOCATABLE actual argument
2187c158e3eSJean Perier    call sma(t8(1))
2197c158e3eSJean Perier
2207c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument
2217c158e3eSJean Perier    call smb(x(:))
2227c158e3eSJean Perier
223016d5a0aSPeter Klausler    !ERROR: Rank of dummy argument is 1, but actual argument has rank 0
2247c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument
2257c158e3eSJean Perier    call smb(x(2))
2267c158e3eSJean Perier
2277c158e3eSJean Perier    !ERROR: ALLOCATABLE dummy argument 'b=' must be associated with an ALLOCATABLE actual argument
2287c158e3eSJean Perier    call smb(x(1:2))
2297c158e3eSJean Perier
2307c158e3eSJean Perier  end subroutine
2317c158e3eSJean Perier
2327c158e3eSJean Perierend module
233fbdcb3ceSPeixinQiao
234fbdcb3ceSPeixinQiaomodule test
235fbdcb3ceSPeixinQiao  type t(l)
236fbdcb3ceSPeixinQiao    integer, len :: l
237fbdcb3ceSPeixinQiao    character(l) :: c
238fbdcb3ceSPeixinQiao  end type
239fbdcb3ceSPeixinQiao
240fbdcb3ceSPeixinQiao contains
241fbdcb3ceSPeixinQiao
242fbdcb3ceSPeixinQiao  subroutine bar(p)
243fbdcb3ceSPeixinQiao    type(t(:)), allocatable :: p(:)
244fbdcb3ceSPeixinQiao  end subroutine
245fbdcb3ceSPeixinQiao
246fbdcb3ceSPeixinQiao  subroutine foo
247fbdcb3ceSPeixinQiao    type(t(10)), allocatable :: p(:)
248fbdcb3ceSPeixinQiao
249fbdcb3ceSPeixinQiao    !ERROR: Dummy and actual arguments must defer the same type parameters when POINTER or ALLOCATABLE
250fbdcb3ceSPeixinQiao    call bar(p)
251fbdcb3ceSPeixinQiao
252fbdcb3ceSPeixinQiao  end subroutine
253fbdcb3ceSPeixinQiao
254fbdcb3ceSPeixinQiaoend module
255