Bug 102745 - CLASS → TYPE check fails after RESHAPE
Summary: CLASS → TYPE check fails after RESHAPE
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 11.3
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
Depends on:
Blocks:
 
Reported: 2021-10-14 14:16 UTC by Tobias Burnus
Modified: 2021-11-23 08:03 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2021-10-14 14:16:34 UTC
Found when working on PR102689

Expected:
* 'CLASS(t)' in the first error message
* an error for passing CLASS(t) to TYPE(t2) in the call with RESHAPE.


implicit none (type, external)
type t
end type t
type, extends(t) :: t2
  integer :: i
end type t2

class(t), allocatable :: A(:), B(:,:,:)

allocate (t2 :: A(100), B(10,10,1))

call bar(A)  ! Rejected (with slightly odd message: Error: Type mismatch in argument ‘x’ at (1); passed CLASS(__class_MAIN___T_1_0a) to TYPE(t2)
call bar(reshape(B, [size(B)]))  ! Wrongly accepted

contains

subroutine bar(x)
  type(t2), intent(in) :: x(:)
end
end
Comment 1 GCC Commits 2021-10-18 07:49:34 UTC
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:017665f63047ce47b087b0b283548a60e5abf3d2

commit r12-4464-g017665f63047ce47b087b0b283548a60e5abf3d2
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Oct 18 09:49:05 2021 +0200

    Fortran: Fix CLASS conversion check [PR102745]
    
            PR fortran/102745
    gcc/fortran/ChangeLog
            * intrinsic.c (gfc_convert_type_warn): Fix checks by checking CLASS
            and do typcheck in correct order for type extension.
            * misc.c (gfc_typename): Print proper not internal CLASS type name.
    
    gcc/testsuite/ChangeLog
            * gfortran.dg/class_72.f90: New.
Comment 2 GCC Commits 2021-10-19 08:52:47 UTC
The releases/gcc-11 branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:3de82c6c36fea8fad7145b62ccb3a7c06d1f3c51

commit r11-9173-g3de82c6c36fea8fad7145b62ccb3a7c06d1f3c51
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Oct 18 09:49:05 2021 +0200

    Fortran: Fix CLASS conversion check [PR102745]
    
            PR fortran/102745
    gcc/fortran/ChangeLog
            * intrinsic.c (gfc_convert_type_warn): Fix checks by checking CLASS
            and do typcheck in correct order for type extension.
            * misc.c (gfc_typename): Print proper not internal CLASS type name.
    
    gcc/testsuite/ChangeLog
            * gfortran.dg/class_72.f90: New.
    
    (cherry picked from commit 017665f63047ce47b087b0b283548a60e5abf3d2)
Comment 3 Tobias Burnus 2021-10-19 10:38:35 UTC
FIXED (for GCC 11 + 12).