Affects versions down to gfortran-8 : $ cat z1.f90 program p type t(n) integer, len :: n character(n) :: c end type type(t(:)), allocatable :: z allocate (t(7) :: z) associate (y => z%c) ! print *, y end associate end $ gfortran-10-20191215 -c z1.f90 z1.f90:8:0: 8 | associate (y => z%c) | internal compiler error: tree check: expected tree that contains 'decl minimal' structure, have 'component_ref' in add_decl_as_local, at fortran/trans-decl.c:261 0x5ef00f tree_contains_struct_check_failed(tree_node const*, tree_node_structure_enum, char const*, int, char const*) ../../gcc/tree.c:9859 0x73e77d contains_struct_check(tree_node*, tree_node_structure_enum, char const*, int, char const*) ../../gcc/tree.h:3387 0x73e77d add_decl_as_local ../../gcc/fortran/trans-decl.c:261 0x73e77d gfc_finish_var_decl ../../gcc/fortran/trans-decl.c:646 0x73d3de gfc_get_symbol_decl(gfc_symbol*) ../../gcc/fortran/trans-decl.c:1829 0x740cbf generate_local_decl ../../gcc/fortran/trans-decl.c:5872 0x6f1dc2 do_traverse_symtree ../../gcc/fortran/symbol.c:4165 0x7358bf generate_local_vars ../../gcc/fortran/trans-decl.c:6078 0x7358bf gfc_process_block_locals(gfc_namespace*) ../../gcc/fortran/trans-decl.c:7089 0x7a7469 gfc_trans_block_construct(gfc_code*) ../../gcc/fortran/trans-stmt.c:2267 0x70b137 trans_code ../../gcc/fortran/trans.c:1960 0x7424cd gfc_generate_function_code(gfc_namespace*) ../../gcc/fortran/trans-decl.c:6801 0x6bc426 translate_all_program_units ../../gcc/fortran/parse.c:6302 0x6bc426 gfc_parse_file() ../../gcc/fortran/parse.c:6541 0x70742f gfc_be_parse_file ../../gcc/fortran/f95-lang.c:210
Started with r8-3056-g5bab4c9631c478b7940e952ea57de680321d5a8e. Before that it was rejected: $ gcc-7 pr92960.f90 -c pr92960.f90:2:3: type t(n) 1 Error: Unclassifiable statement at (1) pr92960.f90:3:14: integer, len :: n 1 Error: Invalid character in name at (1) pr92960.f90:5:6: end type 1 Error: Expecting END PROGRAM statement at (1) pr92960.f90:6:9: type(t(:)), allocatable :: z 1 Error: Derived type ‘t’ at (1) is being used before it is defined pr92960.f90:7:13: allocate (t(7) :: z) 1 Error: Allocate-object at (1) is neither a data pointer nor an allocatable variable pr92960.f90:8:14: associate (y => z%c) 1 Error: Expected association at (1) pr92960.f90:10:6: end associate 1 Error: Expecting END PROGRAM statement at (1) pr92960.f90:4:16: character(n) :: c 1 Error: Variable ‘n’ cannot appear in the expression at (1) pr92960.f90:4:23: character(n) :: c 1 Error: ‘c’ at (1) must have constant character length in this context
Fixed on 12-branch and mainline. I will add the testcase below, when the current patch for some of PR87477 is committed. Thanks Paul ! { dg-do-run } ! ! Contributed by Gerhard Steinmetz <gscfq@t-online.de> ! program p type t(n) integer, len :: n character(n) :: c end type type(t(:)), allocatable :: z allocate (t(7) :: z) z%c = "1234567" associate (y => z%c) if (y .ne. "1234567") stop 1 if (len (y) .ne. 7) stop 2 end associate deallocate (z) end