comp.lang.ada
 help / color / mirror / Atom feed
* Indefinite_Holders: bug or misunderstanding?
@ 2018-01-31 12:06 Alejandro R. Mosteo
  2018-01-31 22:31 ` Shark8
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro R. Mosteo @ 2018-01-31 12:06 UTC (permalink / raw)


I have used the Indefinite_Holders sometimes to make definite types from 
classwide ones, or variant records without defaults. However this sample 
case doesn't work with an array (with GNAT 2017 or GCC 7.2.0) and I'm 
unsure wether it should:

---8<---

with Ada.Containers.Indefinite_Holders;

procedure Test_Holder is

    package Inner is

       type Str (<>) is private;

    private

       type Str is array (Positive range <>) of Character;

       -- type Str (Len : Natural) is record
       --    S : String (1 .. Len);
       -- end record;

    end Inner;

    package Str_Holders is new Ada.Containers.Indefinite_Holders
       (Inner.Str, Inner."=");

begin
    null;
end Test_Holder;

---8<---

The commented alternate Str type does compile fine. The error I'm 
getting for the uncommented one is:

$ gnatmake test_holder.adb
gcc -c test_holder.adb
test_holder.adb:19:04: instantiation error at a-coinho.adb:337
test_holder.adb:19:04: invalid constraint: type has no discriminant
test_holder.adb:19:04: instantiation error at a-coinho.adb:337
test_holder.adb:19:04: unconstrained subtype not allowed (need 
initialization)
test_holder.adb:19:04: provide initial value or explicit array bounds
test_holder.adb:19:04: instantiation error at a-coinho.adb:337
test_holder.adb:19:04: expected private type "Str" defined at line 7
test_holder.adb:19:04: found type "Str" defined at line 11
gnatmake: "test_holder.adb" compilation error

Something obvious I'm missing?

Thanks,
Alex.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Indefinite_Holders: bug or misunderstanding?
  2018-01-31 12:06 Indefinite_Holders: bug or misunderstanding? Alejandro R. Mosteo
@ 2018-01-31 22:31 ` Shark8
  2018-02-01  0:31   ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: Shark8 @ 2018-01-31 22:31 UTC (permalink / raw)


Hm, the error-message is straightforward: the compiler is expecting the full-definition of Str to have a discriminant.

HOWEVER, I seem to remember* the partial-view ("type Str (<>) is private") as indicating only that the type is unconstrained, which the array actually is -- so if that's the proper interpretation then this is a compiler bug.


* I could be misremembering; I don't think that the generic-parameter "Type Param(<>) is private"

---------------------------------
PS -- Looks like a compiler error.

    Generic
	Type Test(<>) is private;
	With Function Image( Item : Test ) Return String;
    Package TTK is
	Procedure Print( Item : Test );
    End TTK;

    Package Body TTK is
	Procedure Print( Item : Test ) is
	Begin
	    Ada.Text_IO.Put_Line( Image(Item) );
	End Print;
    End TTK;
    
    Type B is Array(Integer Range <>) of Integer;
    Function To_String(Object : B) Return String is
	Subtype Tail is Integer range Integer'Succ(Object'First)..Object'Last;
    Begin
	Return (Case Object'Length is
	     when 0 => "",
	     when 1 => Object(Object'First)'Img & '.',
	     when others => Object(Object'First)'Img & ',' & To_String(Object(Tail))
	 );
    End To_String;
    
    Package K is new TTK(B, To_String);
--...
  K.Print( (5,2,3,1,7) );

------------
-- OUTPUT --
------------
 5, 2, 3, 1, 7.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Indefinite_Holders: bug or misunderstanding?
  2018-01-31 22:31 ` Shark8
@ 2018-02-01  0:31   ` Randy Brukardt
  2018-02-01 15:53     ` Alejandro R. Mosteo
  0 siblings, 1 reply; 4+ messages in thread
From: Randy Brukardt @ 2018-02-01  0:31 UTC (permalink / raw)


"Shark8" <onewingedshark@gmail.com> wrote in message 
news:bf840108-2cdb-457d-928e-9db658d4d8d2@googlegroups.com...
> Hm, the error-message is straightforward: the compiler is expecting the 
> full-definition of Str to have a discriminant.
>
> HOWEVER, I seem to remember* the partial-view ("type Str (<>) is private") 
> as indicating only that the type is unconstrained, which the array 
> actually is -- so if that's the proper interpretation then this is a 
> compiler bug.
>
>
> * I could be misremembering; I don't think that the generic-parameter 
> "Type Param(<>) is private"
>
> ---------------------------------
> PS -- Looks like a compiler error.

I agree, looks like a compiler bug to me. Any non-limited type should work 
in a holder.

                           Randy.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Indefinite_Holders: bug or misunderstanding?
  2018-02-01  0:31   ` Randy Brukardt
@ 2018-02-01 15:53     ` Alejandro R. Mosteo
  0 siblings, 0 replies; 4+ messages in thread
From: Alejandro R. Mosteo @ 2018-02-01 15:53 UTC (permalink / raw)


On 01/02/18 01:31, Randy Brukardt wrote:
> "Shark8" <onewingedshark@gmail.com> wrote in message
> news:bf840108-2cdb-457d-928e-9db658d4d8d2@googlegroups.com...
>> Hm, the error-message is straightforward: the compiler is expecting the
>> full-definition of Str to have a discriminant.
>>
>> HOWEVER, I seem to remember* the partial-view ("type Str (<>) is private")
>> as indicating only that the type is unconstrained, which the array
>> actually is -- so if that's the proper interpretation then this is a
>> compiler bug.
>>
>>
>> * I could be misremembering; I don't think that the generic-parameter
>> "Type Param(<>) is private"
>>
>> ---------------------------------
>> PS -- Looks like a compiler error.
> 
> I agree, looks like a compiler bug to me. Any non-limited type should work
> in a holder.
> 
>                             Randy.

That's what I expected. Submitting then.

Thanks,
Álex.

> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-02-01 15:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31 12:06 Indefinite_Holders: bug or misunderstanding? Alejandro R. Mosteo
2018-01-31 22:31 ` Shark8
2018-02-01  0:31   ` Randy Brukardt
2018-02-01 15:53     ` Alejandro R. Mosteo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox