| Thread overview | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 17, 2013 Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Temtaime | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Temtaime | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Temtaime | 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. "Identifiers starting with __ (two underscores) are reserved." http://dlang.org/lex.html#Identifier Ali | |||
May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin Attachments:
| 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 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Temtaime | 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
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply