Bug 38882 - incorrect deferred constant declaration accepted
Summary: incorrect deferred constant declaration accepted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: unknown
: P3 minor
Target Milestone: 13.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2009-01-16 20:12 UTC by Tero Koskinen
Modified: 2024-10-26 10:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 13.0
Known to fail:
Last reconfirmed: 2015-12-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tero Koskinen 2009-01-16 20:12:05 UTC
GCC incorrectly accepts following code with deferred constant declaration:

-- vstrings.ads
-- gnatmake -c -gnatc vstrings.ads
package VStrings is
   subtype VString_Size is Integer range 0 .. 160;

   type VString (Len : VString_Size := VString_Size'Last) is private;

   Empty_VString : constant VString (Len => 0);

private
   type VString (Len : VString_Size := VString_Size'Last) is record
      Data : String (1 .. Len) := (others => ' ');
   end record;

   Empty_VString : constant VString := (Len => 0, Data => (others => ' '));
end VStrings;
-- end

For example Janus/Ada 3.1.2beta gives following error message:
In File C:\koodi\ada\vstrings\VSTRINGS.ADS at line 13
--------------
   12:
   13:     Empty_VString : constant VString := (Len => 0, Data => (others => ' '));
-----------^
*ERROR* Deferred constant's type does not match forward definition (6.4.3) [RM 7.4(5)]

According to RR Software technical support, Janus/Ada correctly rejects
the code, because 
   Empty_VString : constant VString := ...;

does not have constraint at all and does not match its forward definition statically.

Tested GCC versions were GCC 4.3.1 on OpenBSD/i386 and GCC 4.3.2 on Fedora 10/i386.
Comment 1 Eric Botcazou 2015-12-05 17:31:39 UTC
The error is still missing.
Comment 2 Eric Botcazou 2024-10-26 10:24:01 UTC
Fixed in GCC 13 and later:
vstrings.ads:13:04: error: subtype does not statically match deferred declaration at line 6