More Clang diagnostic

bearophile bearophileHUGS at lycos.com
Mon Oct 25 17:03:12 PDT 2010


LLVM devs keep adding new nice things to Clang diagnostic, so here I am again to show them:
http://clang.llvm.org/diagnostics.html


The first nice diagnostic feature is the usage of "aka":

  t.c:13:9: error: member reference base type 'pid_t' (aka 'int') is not a structure or union
    myvar = myvar.x;
            ~~~~~ ^

Some time ago I have added an enhancement request on this:
http://d.puremagic.com/issues/show_bug.cgi?id=5004

For me there's no doubt this is a nice little diagnostic feature to have in D too, is it doable in D/DMD?

--------------------

Another diagnostic feature is to not just use the caret (we have discussed about it time ago) but it also underlines the wrong part:

  t.c:7:39: error: invalid operands to binary expression ('int' and 'struct A')
    return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);
                         ~~~~~~~~~~~~~~ ^ ~~~~~

--------------------

"Fix-it Hints" are a diagnostic feature that I think is generally missing in D, it is related to the compiler hints I have discussed about time ago. It says how to fix localized problems (the next step for compilers is to fix the source code themselves :-) ):


  $ clang t.c
  t.c:5:28: warning: use of GNU old-style field designator extension
  struct point origin = { x: 0.0, y: 0.0 };
                          ~~ ^
                          .x = 
  t.c:5:36: warning: use of GNU old-style field designator extension
  struct point origin = { x: 0.0, y: 0.0 };
                                  ~~ ^
                                  .y = 


  $ clang t.c
  t.c:4:8: error: expected ';' after expression
    bar()
         ^
         ;

--------------------

Regarding the section titled "Quality of Implementation and Attention to Detail"

This is the Clang error:


t.c:5: error: expected ';' before '}' token
$ clang t.c
t.c:4:8: error: expected ';' after expression
  bar()
       ^
       ;


And this may be an equivalent D program (the C code that generates the error isn's shown):


void foo() {}

void main() {
    foo()
}


DMD 2.049 shows a worse error message:

test.d(5): found '}' when expecting ';' following statement
test.d(5): found 'EOF' when expecting '}' following compound statement

I'd like the missing ; error to refer to where it's actually missing, in D code.


Recently I have added a bug report that may be related:
http://d.puremagic.com/issues/show_bug.cgi?id=5114

----------------------------

The last example from that page, the error message shown by Clang:


$ gcc-4.2 t.c
t.c:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
$ clang t.c
t.c:3:1: error: unknown type name 'foo_t'
foo_t *P = 0;
^


A possible D version of the invisible C code:


void main() {
    foo_t *P = null;
}


Unfortunately here DMD 2.049 acts very badly:

test.d(2): Error: identifier 'foo_t' is not defined
test.d(2): Error: foo_t is used as a type
Assertion failure: 'tn->mod == MODimmutable' on line 879 in file 'mtype.c'


So I've just added a bug report, I don't know if it's a dupe:
http://d.puremagic.com/issues/show_bug.cgi?id=5119

Bye,
bearophile


More information about the Digitalmars-d mailing list