digitalmars.D.learn - Compiler bug ?
- Temtaime (15/15) May 17 2013 struct A {
- Namespace (3/3) May 17 2013 I don't see where k comes from?
- Maxim Fomin (6/9) May 17 2013 I think the point is that it comes from nowhere. Compiler
- Temtaime (3/3) May 17 2013 Yes, i want to see 'undeclared variable' error, but the compiler
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/7) May 17 2013 "Identifiers starting with __ (two underscores) are reserved...
- Jonathan M Davis (8/12) May 17 2013 Identifiers begining with two underscores are reserved by the compiler, ...
- bearophile (5/6) May 17 2013 Ideally you are right. But I think sometimes you want to use
- Namespace (2/11) May 17 2013 Ok, not always, but mostly it's a bad idea.
- 1100110 (3/14) May 17 2013 It is not the D way to forbid you from shooting yourself in the foot.
- Jonathan M Davis (11/17) May 17 2013 D will stop you from shooting yourself in the foot if it can do so in a ...
- bearophile (7/18) May 17 2013 I think to answer this issue we need someone that knows more
- Jonathan M Davis (5/9) May 17 2013 Oh, I'm sure that it would be possible. It's just a question of how
- 1100110 (4/15) May 17 2013 I love how we are all basically agreeing with one another, even though
- Timon Gehr (2/17) May 18 2013 It is trivial to catch them in the parser.
- bearophile (4/5) May 18 2013 So the question is: is it right to catch them all? :-)
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (8/10) May 18 2013 I don't think so. Double underscores are reserved for the
- Maxim Fomin (7/35) May 17 2013 The only scenario when __identifiers are needed which came to my
- Jesse Phillips (6/7) May 17 2013 I'm pretty sure the answer is:
- bearophile (8/12) May 17 2013 It's a bad error message, but it's correct, because k doesn't
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
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
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
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:Ok, not always, but mostly it's a bad idea.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
On 05/17/2013 09:35 AM, Maxim Fomin wrote:On Friday, 17 May 2013 at 14:12:10 UTC, Namespace wrote:It is not the D way to forbid you from shooting yourself in the foot. goto, catch(Throwable th), there are plenty more examples.I don't see where k comes from?=20 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. =20And it's always a bad idea to prefix a variable with '__', because this is reserved to the compiler.=20 If it alwalys a bad idea, compiler should not accept such code.
May 17 2013
On Friday, May 17, 2013 11:59:38 1100110 wrote:On 05/17/2013 09:35 AM, Maxim Fomin wrote:D will stop you from shooting yourself in the foot if it can do so in a way that doesn't actually limit you, and it does do quite a few things to make it harder to shoot yourself in the foot, but it certainly doesn't ultimately stop you from doing so. However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the semantic analysis to check whether variables started with underscores, in which case, catching the user's variables that start with two underscores while permitting the compiler's variables could get tricky. - Jonathan M DavisIf 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
Jonathan M Davis:However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the semantic analysis to check whether variables started with underscores, in which case, catching the user's variables that start with two underscores while permitting the compiler's variables could get tricky.I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it. Bye, bearophile
May 17 2013
On Friday, May 17, 2013 19:19:46 bearophile wrote:I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it.Oh, I'm sure that it would be possible. It's just a question of how complicated that would be and whether it's worth it given that very few programmers try and declare variables which start with two underscores. - Jonathan M Davis
May 17 2013
On 05/17/2013 12:27 PM, Jonathan M Davis wrote:On Friday, May 17, 2013 19:19:46 bearophile wrote:=20I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it.=20 Oh, I'm sure that it would be possible. It's just a question of how=20 complicated that would be and whether it's worth it given that very few=programmers try and declare variables which start with two underscores.==20 - Jonathan M DavisI love how we are all basically agreeing with one another, even though we are saying such different things.
May 17 2013
On 05/17/2013 07:19 PM, bearophile wrote:Jonathan M Davis:It is trivial to catch them in the parser.However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the semantic analysis to check whether variables started with underscores, in which case, catching the user's variables that start with two underscores while permitting the compiler's variables could get tricky.I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it. Bye, bearophile
May 18 2013
Timon Gehr:It is trivial to catch them in the parser.So the question is: is it right to catch them all? :-) Bye, bearophile
May 18 2013
On 05/18/2013 11:50 AM, bearophile wrote:> Timon Gehr:I don't think so. Double underscores are reserved for the "implementation", which includes the standard library. I don't think the compiler should know that it is compiling something that is part of Phobos. It could even be a mixin that has such a variable that is implemented in Phobos. There is nothing wrong in reminder each other that a name is reserved. :) AliIt is trivial to catch them in the parser.So the question is: is it right to catch them all? :-)
May 18 2013
On Friday, 17 May 2013 at 17:08:31 UTC, Jonathan M Davis wrote:On Friday, May 17, 2013 11:59:38 1100110 wrote:The only scenario when __identifiers are needed which came to my mind is case when working with C or os implementation. Low-level implementation supposed to use '__' namespace because of practice encouraged by ISO C and other docs to reserve space for user and system specific identifiers. Probably double leading underscores should be restricted to extern declarations.On 05/17/2013 09:35 AM, Maxim Fomin wrote:D will stop you from shooting yourself in the foot if it can do so in a way that doesn't actually limit you, and it does do quite a few things to make it harder to shoot yourself in the foot, but it certainly doesn't ultimately stop you from doing so. However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the semantic analysis to check whether variables started with underscores, in which case, catching the user's variables that start with two underscores while permitting the compiler's variables could get tricky. - Jonathan M DavisIf 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, 17 May 2013 at 14:35:35 UTC, Maxim Fomin wrote:If it alwalys a bad idea, compiler should not accept such code.I'm pretty sure the answer is: Compilers can have different extensions, it would be bad for a compiler to reject code which is valid by another compiler. That said, I don't know of any rules around ignoring these as there is for pragma.
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