Logical const
Andrej Mitrovic
andrej.mitrovich at gmail.com
Mon Nov 29 18:27:08 PST 2010
Oh this one is even more spectacular:
void bar( ref int n )
{
n++;
}
void main( string[] args )
{
immutable int n = args.length * 0;
assert( is( typeof( n ) == const(int) ) );
bar( n ); // Uhm...
assert( n == 1 );
}
K:\code>dmd bug.d -release -O -inline
K:\code>bug
object.Error: assert(0) or HLT instruction
I'll update the bugzilla entry.
On 11/30/10, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> On 11/30/10, Simen kjaeraas <simen.kjaras at gmail.com> wrote:
>> Simen kjaeraas <simen.kjaras at gmail.com> wrote:
>>
>>> It works in many cases, but not for function calls
>>
>> Some more testing brought this bug to my attention:
>>
>> void bar( ref int n ) {
>> n++;
>> }
>>
>> void main( string[] args ) {
>> const int n = args.length * 0;
>> assert( is( typeof( n ) == const(int) ) );
>> bar( n ); // Uhm...
>> assert( n == 1 ); // WTF?!?
>> }
>>
>>
>> I would say this is seriously bad.
>> http://d.puremagic.com/issues/show_bug.cgi?id=5291
>>
>>
>> --
>> Simen
>>
>
> It seems this is a problem with ref. If you use "in" the compiler gets
> some of its senses back:
>
> void bar( in int n )
> {
> n++;
> }
>
> void main( string[] args )
> {
> const int n = args.length * 0;
> assert( is( typeof( n ) == const(int) ) );
> bar( n ); // compile error
> assert( n == 1 );
> }
>
More information about the Digitalmars-d
mailing list