Bug 15611 - Invalid program not detected, RM 3.7(11)
Summary: Invalid program not detected, RM 3.7(11)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2004-05-23 09:44 UTC by Ludovic Brenta
Modified: 2011-08-31 07:04 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail: 4.0.0
Last reconfirmed: 2007-12-13 13:57:22


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ludovic Brenta 2004-05-23 09:44:16 UTC
-- RM 3.7(11)
-- No default expressions are permitted in a known_discriminant_part
-- in a declaration of a tagged type or a generic formal type.
package Test_244943 is
   type T (n: Natural := 10) is private;
private
   type T (n: Natural := 10) is tagged  -- ERROR: no default allowed
      null record;
end Test_244943;

The compiler says nothing; I was expecting something like:

test_244943:7:22: no default value allowed for discriminant N
Comment 1 Andrew Pinski 2004-10-29 14:45:13 UTC
Confirmed.
Comment 2 Samuel Tardieu 2007-11-26 20:46:07 UTC
Ludovic,

are you sure that this applies when a tagged type is used as a completion of a private type with discriminants having default expressions?

This case is handled specially in GNAT sources. sem_ch3.adb reads:

            --  Tagged types cannot have defaulted discriminants, but a
            --  non-tagged private type with defaulted discriminants
            --   can have a tagged completion.
Comment 3 Ludovic Brenta 2007-11-30 21:51:27 UTC
7.3(15) says that a private type has a partial view and a full view, and the properties of the partial view apply in some places, and the properties of the full view apply in other places.  So in places where the full view applies, the type is considered tagged, and cannot have default expressions in the known_discriminant part.

You seem to imply that the full view does not apply in the completion of the type, as the full view does not even exist yet.  Taking the RM literally, you may be right but the annotated AARM 3.7(11.b/2) provides guidance:

   Defaults for discriminants of tagged types are disallowed so that
   every object of a tagged type is constrained, either by an explicit
   constraint, or by its initial discriminant values. This substantially
   simplifies the semantic rules and the implementation of inherited
   dispatching operations. For generic formal types, the restriction
   simplifies the type matching rules. If one simply wants a "default"
   value for the discriminants, a constrained subtype can be declared for
   future use.

I think this rule would be violated for objects of the type declared in the private part where the full view applies, i.e. you could declare unconstrained objects of the tagged type.

So, I confirm this to be a bug.
Comment 4 Samuel Tardieu 2007-12-13 13:57:22 UTC
Confirmed on 4.3.0 20071213
Comment 5 Ludovic Brenta 2009-08-06 20:29:47 UTC
Confirmed on 4.4.1.
Comment 6 nicolas.boulenguez 2011-08-30 23:33:54 UTC
Fixed in 4.6.1
Comment 7 Arnaud Charlet 2011-08-31 07:04:21 UTC
Closing then:

$ gcc -c test_244943.ads
test_244943.ads:4:26: discriminants of tagged type cannot have defaults