http://d.puremagic.com/issues/show_bug.cgi?id=4375



--- Comment #2 from bearophile_h...@eml.cc 2010-06-23 10:23:48 PDT ---
Answer to Comment 1:

>I don't believe that it cares at all about indentation at this point.<

Right, with this code GCC generates the same warning/error:

void foo() {}
void bar() {}
int main() {
    int a = 1;
    int b = 1;
    if (a)
        if (b)
            foo();
        else
            bar();
    return 0;
}


In the original code I have uses a wrong indentation to better show a possible
semantic bug that can happen.


> Requiring it to be able to understand indentation well enough to alert the
> programmer as to where they used it incorrectly or to complain that the
> programmer has used it in a manner which could be ambiguous to a human reader
> would likely complicate things quite a bit for the compiler.

I think some lint do this, but I was not asking for D to do this. Sorry if I
have written misleading things.


>The current situation is totally unambiguous.<

The current situation is totally unambiguous for the compiler. But
unfortunately in some situations it is not unambiguous for some programmers.
The purpose of that GCC warning it to help programmers, it's not for the
compiler.


> Also, it could be rather nasty to code generators, since then they'd have to
> worry a lot more about making code human-readable - which while potentially
> nice probably isn't necessary in many cases.

In the original Description I have expressed my desires in a bad way. My
enhancement request doesn't regard indentation at all, so there are no problems
with code generators (that probably always use braces).


> I believe that the usual solution if a programmer is worried about this sort 
> of
> thing is just to use a coding standard that always requires braces for the
> bodies of if-else statements, loops, etc.

If you always use braces, then you will never see this error I am asking for,
so you can ignore this enhancement request, it's not for you. A sufficiently
careful programmer can avoid most bugs. But programmers are not always fully
careful, so it's good if the compiler guards for _easy to catch_ possible
sources of bugs. D syntax differs from C syntax in some small parts also to
catch common bugs.

I don't know if D devs/programmers agree with GCC devs that this is an
important enough possible source of bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to