https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118589
--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> --- Created attachment 60268 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60268&action=edit Proposed fix which detects an opaque type and improves error recovery and error accuracy Proposed fix detects an opaque type access and issues an error. It also improves the accuracy of the error case and reduces the noise of cascaded errors. For example: $ cat opaquedefs.def DEFINITION MODULE opaquedefs ; TYPE OpaqueA ; OpaqueB ; END opaquedefs. $ cat opaquedefs.mod (* { dg-do compile } *) (* { dg-options "-g -c" } *) IMPLEMENTATION MODULE opaquedefs ; TYPE OpaqueA = POINTER TO CARDINAL ; OpaqueB = POINTER TO RECORD width : CARDINAL ; height: CARDINAL ; END ; END opaquedefs. $ cat badopaque.mod (* { dg-do compile } *) (* { dg-options "-g" } *) MODULE badopaque ; FROM opaquedefs IMPORT OpaqueA ; VAR a: OpaqueA ; c: CARDINAL ; BEGIN c := 123 ; a^ := c (* { dg-error "with an opaque type" } *) END badopaque. $ gm2 -c badopaque.mod badopaque.mod:14:5: error: In program module ‘badopaque’: ‘a’ is declared with an opaque type from a different module and cannot be dereferenced 14 | a^ := c (* { dg-error "with an opaque type" } *) | ^ $ cat badopaque2.mod (* { dg-do compile } *) (* { dg-options "-g" } *) MODULE badopaque2 ; FROM opaquedefs IMPORT OpaqueB ; VAR b: OpaqueB ; c: CARDINAL ; BEGIN c := 123 ; b^.width := c (* { dg-bogus "unnamed" } *) (* { dg-error "cannot be dereferenced" "b^.width" { target *-*-* } 14 } *) (* { dg-error "has no field" "no field" { target *-*-* } 14 } *) END badopaque2. $ gm2 -c badopaque2.mod badopaque2.mod:14:5: error: In program module ‘badopaque2’: ‘b’ is declared with an opaque type from a different module and cannot be dereferenced 14 | b^.width := c (* { dg-bogus "unnamed" } *) | ^ badopaque2.mod:14:4: error: the type of ‘bad opaque pointer dereference’ is not a record (but ‘ADDRESS’) and therefore it has no field 14 | b^.width := c (* { dg-bogus "unnamed" } *) | ^~