Thread overview | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 05, 2016 Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Hi Guys, What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ? int fn(int y) { int x = void; ++x; return x+y; } This requires data-flow analysis (The same kind that tells you if you are skipping a statement) And will slow down compilation a little if we enable such a warning. |
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
> And will slow down compilation a little if we enable such a warning.
I have thought it over again. We can make it such that, hit will be unnoticeable if you never use = void.
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
> Hi Guys,
> What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ?
>
> int fn(int y)
> {
> int x = void;
> ++x;
> return x+y;
> }
>
> This requires data-flow analysis (The same kind that tells you if you are skipping a statement)
> And will slow down compilation a little if we enable such a warning.
no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU.
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Monday, 5 December 2016 at 04:59:01 UTC, ketmar wrote:
> On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
>> Hi Guys,
>> What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ?
>>
>> int fn(int y)
>> {
>> int x = void;
>> ++x;
>> return x+y;
>> }
>>
>> This requires data-flow analysis (The same kind that tells you if you are skipping a statement)
>> And will slow down compilation a little if we enable such a warning.
>
> no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU.
Even if you want that ub.
A warning will not halt the compilation.
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | Dne 5.12.2016 v 06:03 Stefan Koch via Digitalmars-d napsal(a):
> On Monday, 5 December 2016 at 04:59:01 UTC, ketmar wrote:
>> On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
>>> Hi Guys,
>>> What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ?
>>>
>>> int fn(int y)
>>> {
>>> int x = void;
>>> ++x;
>>> return x+y;
>>> }
>>>
>>> This requires data-flow analysis (The same kind that tells you if you are skipping a statement)
>>> And will slow down compilation a little if we enable such a warning.
>>
>> no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU.
>
> Even if you want that ub.
> A warning will not halt the compilation.
Yes, but still will be there. I always try to have no warnings, maybe as a special compilation flag could enable this.
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Monday, 5 December 2016 at 07:25:20 UTC, Daniel Kozak wrote:
> Dne 5.12.2016 v 06:03 Stefan Koch via Digitalmars-d napsal(a):
>
>> On Monday, 5 December 2016 at 04:59:01 UTC, ketmar wrote:
>>> On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
>>>> Hi Guys,
>>>> What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ?
>>>>
>>>> int fn(int y)
>>>> {
>>>> int x = void;
>>>> ++x;
>>>> return x+y;
>>>> }
>>>>
>>>> This requires data-flow analysis (The same kind that tells you if you are skipping a statement)
>>>> And will slow down compilation a little if we enable such a warning.
>>>
>>> no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU.
>>
>> Even if you want that ub.
>> A warning will not halt the compilation.
> Yes, but still will be there. I always try to have no warnings, maybe as a special compilation flag could enable this.
It will warn on something that is almost always bad!
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | Dne 5.12.2016 v 08:39 Stefan Koch via Digitalmars-d napsal(a): > On Monday, 5 December 2016 at 07:25:20 UTC, Daniel Kozak wrote: >> Dne 5.12.2016 v 06:03 Stefan Koch via Digitalmars-d napsal(a): >> >>> On Monday, 5 December 2016 at 04:59:01 UTC, ketmar wrote: >>>> On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote: >>>>> Hi Guys, >>>>> What is your opinion, should we warn if we unambiguously detect something that is clearly unwanted ? >>>>> >>>>> int fn(int y) >>>>> { >>>>> int x = void; >>>>> ++x; >>>>> return x+y; >>>>> } >>>>> >>>>> This requires data-flow analysis (The same kind that tells you if you are skipping a statement) >>>>> And will slow down compilation a little if we enable such a warning. >>>> >>>> no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU. >>> >>> Even if you want that ub. >>> A warning will not halt the compilation. >> Yes, but still will be there. I always try to have no warnings, maybe as a special compilation flag could enable this. > > It will warn on something that is almost always bad! https://github.com/g0tmi1k/debian-ssh#information |
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, 5 December 2016 at 05:03:36 UTC, Stefan Koch wrote:
> A warning will not halt the compilation.
it will: all my projects are built in "-Werror" mode (the only warning i made explicitly switchable in dmd is "statement unreachable" -- it is completely useless for me).
i'd prefer to have `pragma(warning/info, msg);` instead, so i can issue informational messages when i want to.
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Monday, December 05, 2016 05:03:36 Stefan Koch via Digitalmars-d wrote:
> On Monday, 5 December 2016 at 04:59:01 UTC, ketmar wrote:
> > On Monday, 5 December 2016 at 04:41:55 UTC, Stefan Koch wrote:
> >> Hi Guys,
> >> What is your opinion, should we warn if we unambiguously
> >> detect something that is clearly unwanted ?
> >>
> >> int fn(int y)
> >> {
> >>
> >> int x = void;
> >> ++x;
> >> return x+y;
> >>
> >> }
> >>
> >> This requires data-flow analysis (The same kind that tells
> >>
> >> you if you are skipping a statement)
> >> And will slow down compilation a little if we enable such a
> >> warning.
> >
> > no need to. if i explicitly wrote `=void` there, i know what i am doing. maybe i want that UB. or something. and i tried to tell the compiler STFU. please, don't make it harder, and don't force me to invent another ways to say STFU.
>
> Even if you want that ub.
> A warning will not halt the compilation.
It will with -w. And even if you build with -wi, it's bad practice to leave warnings in. So, really, we should _never_ warn about anything where it would be reasonable for the programmer to not fix whatever is causing the warning.
That being said, if we're dealing with something that is clearly never okay, a warning is fine. And I don't know how anyone can claim that doing something like ++x on a variable that was initialized with null or void is rasonable. But if such a warning were introduced, it would have to be done carefully and only used when it was totally certain that what the programmer was doing was invalid. For instance, taking the address of the variable or passing it to a function would potentially be perfectly fine, whereas calling a member function on it when nothing could have possibly given it a value wouldn't be.
Java sometimes gets annoying with how it requires that you initialize a variable before you use it, because its detection simply isn't smart enough, and we don't want to get into a similar boat with D. So, if such detection really _is_ smart enough, then fine, but it should never have false positives, or it's making things worse than they are now.
- Jonathan M Davis
|
December 05, 2016 Re: Should we warn if we detect null derefernces or void value uses ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On 12/04/2016 11:41 PM, Stefan Koch wrote:
> Hi Guys,
> What is your opinion, should we warn if we unambiguously detect
> something that is clearly unwanted ?
>
> int fn(int y)
> {
> int x = void;
> ++x;
> return x+y;
> }
No new warnings please. If something (such as the above) is definitely wrong - the code is not memory unsafe but is definitely in error - then just issue an error. That should be done whether or not the function is used in CTFE. -- Andrei
|
Copyright © 1999-2021 by the D Language Foundation