Jump to page: 1 2
Thread overview
Compiler bug ?
May 17, 2013
Temtaime
May 17, 2013
Namespace
May 17, 2013
Maxim Fomin
May 17, 2013
Temtaime
May 17, 2013
Ali Çehreli
May 17, 2013
Jonathan M Davis
May 17, 2013
bearophile
May 17, 2013
Namespace
May 17, 2013
1100110
May 17, 2013
Jonathan M Davis
May 17, 2013
bearophile
May 17, 2013
Jonathan M Davis
May 17, 2013
1100110
May 18, 2013
Timon Gehr
May 18, 2013
bearophile
May 18, 2013
Ali Çehreli
May 17, 2013
Maxim Fomin
May 18, 2013
Jesse Phillips
May 17, 2013
bearophile
May 17, 2013
struct A {
	int opBinary(string op)(A) { k++; return 0; }
}

struct B {
	A __a;
	alias __a this;
}

void main() {
    B b;
    auto c = b * b;
}


This code doesn't compiles with an error:
Error: 'b' is not of arithmetic type, it is a B

If i remove k++, then it's OK. It seems that compiler omitting the function if there an error in it.
May 17, 2013
I don't see where k comes from?
And it's always a bad idea to prefix a variable with '__', because this is reserved to the compiler.
May 17, 2013
On Friday, 17 May 2013 at 14:12:10 UTC, Namespace wrote:
> I don't see where k comes from?

I think the point is that it comes from nowhere. Compiler incorectly omits two errors from output: "Error undefined indentifier" and "template instance error instantiation". This should go to bugzilla.

> And it's always a bad idea to prefix a variable with '__', because this is reserved to the compiler.

If it alwalys a bad idea, compiler should not accept such code.
May 17, 2013
Yes, i want to see 'undeclared variable' error, but the compiler omits function declaration instead.

And why i shouldn't use __? I think it's ordinary identifier.
May 17, 2013
Temtaime:

> This code doesn't compiles with an error:
> Error: 'b' is not of arithmetic type, it is a B
>
> If i remove k++, then it's OK. It seems that compiler omitting the function if there an error in it.

It's a bad error message, but it's correct, because k doesn't exists. This error message is so bad because opBinary is a template.

In Bugzilla there is a request for an improvement related to this:
http://d.puremagic.com/issues/show_bug.cgi?id=9715

Bye,
bearophile
May 17, 2013
Maxim Fomin:

> If it alwalys a bad idea, compiler should not accept such code.

Ideally you are right. But I think sometimes you want to use those reserved names... So I don't know.

Bye,
bearophile
May 17, 2013
On Friday, 17 May 2013 at 14:35:35 UTC, Maxim Fomin wrote:
> On Friday, 17 May 2013 at 14:12:10 UTC, Namespace wrote:
>> I don't see where k comes from?
>
> I think the point is that it comes from nowhere. Compiler incorectly omits two errors from output: "Error undefined indentifier" and "template instance error instantiation". This should go to bugzilla.
>
>> And it's always a bad idea to prefix a variable with '__', because this is reserved to the compiler.
>
> If it alwalys a bad idea, compiler should not accept such code.

Ok, not always, but mostly it's a bad idea.
May 17, 2013
On 05/17/2013 07:40 AM, Temtaime wrote:
> Yes, i want to see 'undeclared variable' error, but the compiler omits
> function declaration instead.
>
> And why i shouldn't use __? I think it's ordinary identifier.

"Iden­ti­fiers start­ing with __ (two un­der­scores) are re­served."

  http://dlang.org/lex.html#Identifier

Ali

May 17, 2013
On 05/17/2013 09:35 AM, Maxim Fomin wrote:
> On Friday, 17 May 2013 at 14:12:10 UTC, Namespace wrote:
>> I don't see where k comes from?
> 
> I think the point is that it comes from nowhere. Compiler incorectly omits two errors from output: "Error undefined indentifier" and "template instance error instantiation". This should go to bugzilla.
> 
>> And it's always a bad idea to prefix a variable with '__', because this is reserved to the compiler.
> 
> If it alwalys a bad idea, compiler should not accept such code.

It is not the D way to forbid you from shooting yourself in the foot.

goto, catch(Throwable th), there are plenty more examples.



May 17, 2013
On Friday, May 17, 2013 16:40:23 Temtaime wrote:
> Yes, i want to see 'undeclared variable' error, but the compiler omits function declaration instead.
> 
> And why i shouldn't use __? I think it's ordinary identifier.

Identifiers begining with two underscores are reserved by the compiler, which is why identifiers such as __FILE__, __LINE__, __traits, and __gshared all begin with two underscores. Identifiers that the compiler generates are going to start with two underscores, and you could end up with bugs in your program if you happened to declare an identifier with a name that matched a compiler generated one. I believe that that's the case with most C-based languages.

- Jonathan M Davis
« First   ‹ Prev
1 2