public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Arnaud Charlet <charlet@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Justin Squirek <squirek@adacore.com>
Subject: [Ada] Spurious compile failure with nested packages
Date: Tue, 25 Apr 2017 09:01:00 -0000	[thread overview]
Message-ID: <20170425085701.GA47378@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]

This patch adds another condition to an edge case used to delay expression
function freezing (P804-015). The offending package is within the body of a
library-level unit where this edge-case does not apply. By adding a condition
that only delays freezing of expression functions if we are in a library-level
spec we can avoid spurious disambiguation errors.

------------
-- Source --
------------

--  pkg.ads

package Pkg is
   pragma Elaborate_Body;
end;

--  pkg.adb

with Ada.Containers.Vectors;
package body Pkg is
   package SubPkg1 is
      type T1 is private;
      function Foo (T : T1) return Boolean is (True);
      subtype ST1 is T1 with Dynamic_Predicate => Foo (ST1);
   private
      type T1 is null record;
   end;

   package SubPkg2 is
      type T2 is private;
      function Foo (T : T2) return Boolean is (True);
   private
      package V2 is new Ada.Containers.Vectors
        (Positive, SubPkg1.ST1, SubPkg1."=");
      type T2 is record
         SubPkg1 : V2.Vector;
      end record;
   end;

   type C is record
      Count : Natural;
   end record;
   type CA is array (1 .. 3) of C;

   package VC is new Ada.Containers.Vectors (Positive, CA);
   V : VC.Vector;

   procedure Bar is
   begin
      for P in V.Iterate loop
         for X of V (P) loop
            X.Count := X.Count - 1;
         end loop;
      end loop;
   end;
end;

----------------------------
-- Compilation and output --
----------------------------

$ gcc -c pkg.adb
pkg.adb:15:07: warning: in instantiation at a-convec.ads:375
pkg.adb:15:07: warning: component of "Elements_Array" padded by 8 bits

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-04-25  Justin Squirek  <squirek@adacore.com>

	* sem_ch3.adb (Analyze_Declarations): Add
	additional condition for edge case.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 652 bytes --]

Index: sem_ch3.adb
===================================================================
--- sem_ch3.adb	(revision 247146)
+++ sem_ch3.adb	(working copy)
@@ -2646,6 +2646,8 @@
               and then Was_Expression_Function (Next_Decl)
               and then not Is_Compilation_Unit (Current_Scope)
               and then not Is_Generic_Instance (Current_Scope)
+              and then not In_Package_Body
+                             (Enclosing_Lib_Unit_Entity (Current_Scope))
             then
                --  Loop through all entities in the current scope to identify
                --  an instance of the edge case outlined above and ignore

             reply	other threads:[~2017-04-25  8:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25  9:01 Arnaud Charlet [this message]
2017-04-25  9:24 Arnaud Charlet

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=20170425085701.GA47378@adacore.com \
    --to=charlet@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=squirek@adacore.com \
    /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).