https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118589
Bug ID: 118589 Summary: Bug opaque type fields are visible outside implementation module Product: gcc Version: 14.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: modula2 Assignee: gaius at gcc dot gnu.org Reporter: gaius at gcc dot gnu.org Target Milestone: --- As reported on the gm2 mailing list: Opaque type fields are visible outside the implementation module. Consider: $ cat MinOpaque.def DEFINITION MODULE MinOpaque; TYPE Opaque; PROCEDURE Make (VAR o: Opaque; i: INTEGER); END MinOpaque. $ cat MinOpaque.mod: IMPLEMENTATION MODULE MinOpaque; FROM Storage IMPORT ALLOCATE, DEALLOCATE; FROM SYSTEM IMPORT TSIZE; TYPE Opaque = POINTER TO INTEGER; PROCEDURE Make (VAR o: Opaque; i: INTEGER); BEGIN ALLOCATE (o, TSIZE (Opaque)); o^ := i; END Make; END MinOpaque. $ cat TryMinOpaque.mod MODULE TryMinOpaque; FROM InOut IMPORT WriteString, WriteLn, WriteInt; FROM MinOpaque IMPORT Opaque, Make; VAR o: Opaque; BEGIN Make (o, 10); o^ := 20; (* I thought this was illegal. *) WriteString ("o^: "); WriteInt (o^, 0); WriteLn; END TryMinOpaque. The compiler should forbid access to the internals of the Opaque type. $ gm2 --version gm2 (GCC) 14.2.1 20250110 (Red Hat 14.2.1-7) Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This is on Fedora 41 with $ uname -a Linux atla 6.12.8-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jan 2 19:26:03 UTC 2025 x86_64 GNU/Linux