public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Artem dot Andreev at oktetlabs dot ru" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ada/38975]  New: deferred constants of not null access types are not possible
Date: Mon, 26 Jan 2009 12:28:00 -0000	[thread overview]
Message-ID: <bug-38975-17228@http.gcc.gnu.org/bugzilla/> (raw)

The following does not compile:

package Test is
    type X is new Positive;
    type X_Access is not null access constant X;

    Y : constant X_Access;
private
    Y_Val : aliased constant X := 1;
    Y : constant X_Access := Y_Val'Access;
end Test;

with the following diagnostics:
test.ads:6:09: warning: (Ada 2005) null-excluding objects must be initialized
test.ads:6:09: warning: "Constraint_Error" will be raised at run time
test.ads:11:09: "Y" conflicts with declaration at line 6

If "not null" modifier is removed, everything is fine.

As I can see from the following code, the semantic analyzer sees a deferred
constant and (erroneously) assumes that it's an uninitialized object. It then
inserts an implicit null initialization. And when it comes to a full definition
of the constant, the compiler thinks it has been already defined:

(gcc/ada/checks.adb, procedure Null_Exclusion_Static_Checks, line 2728):
     if K = N_Object_Declaration
        and then No (Expression (N))
        and then not No_Initialization (N)
      then
         --  Add an expression that assigns null. This node is needed by
         --  Apply_Compile_Time_Constraint_Error, which will replace this with
         --  a Constraint_Error node.

         Set_Expression (N, Make_Null (Sloc (N)));
         Set_Etype (Expression (N), Etype (Defining_Identifier (N)));

         Apply_Compile_Time_Constraint_Error
           (N      => Expression (N),
            Msg    => "(Ada 2005) null-excluding objects must be initialized?",
            Reason => CE_Null_Not_Allowed);
      end if;

The code can be traced back to at least gcc 4.1.2


-- 
           Summary: deferred constants of not null access types are not
                    possible
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Artem dot Andreev at oktetlabs dot ru


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38975


             reply	other threads:[~2009-01-26 12:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-26 12:28 Artem dot Andreev at oktetlabs dot ru [this message]
2009-10-03 10:11 ` [Bug ada/38975] " sam at gcc dot gnu dot org
2009-10-03 10:32 ` ebotcazou at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-38975-17228@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).