Clang error recovery

bearophile bearophileHUGS at lycos.com
Tue Apr 6 05:05:05 PDT 2010


This is the latest post on the LLVM blog, "Amazing feats of Clang Error Recovery", by Chris Lattner:
http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html

I've compared dmd to few of those examples of Clang usage. I don't comment each one of those things because some of them are specific of C++, and because I don't understand some other of them. If you can write better translations to D or if you understand more of them, you can add and show me more comparisons :-)

=============================

Clang:


int foo(int x, pid_t y) {
  return x+y;
}


t.c:1:16: error: unknown type name 'pid_t'
int foo(int x, pid_t y) {
               ^

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

dmd 2.042:

int foo(int x, pid_t y) {
  return x+y;
}
void main() {}


temp.d(1): Error: identifier 'pid_t' is not defined
temp.d(1): Error: pid_t is used as a type
temp.d(1): Error: cannot have parameter of type void

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

Here Clangs gives a single error message (and it gives the error column).
Here the errors given by dmd give the same information.
Here dmd gives error messages that are better than GCC 4.2 ones, but I think a single good error message is better than three.

=============================

Clang:


#include <inttypes.h>
int64 x;


t.c:2:1: error: unknown type name 'int64'; did you mean 'int64_t'?
int64 x;
^~~~~
int64_t

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

dmd:

I am not sure if this is the same situation:

alias uint uint64_t;
int foo(uint64 x) {
  return x * 2;
}
void main() {}


dmd prints:

temp.d(2): Error: identifier 'uint64' is not defined
temp.d(2): Error: uint64 is used as a type
temp.d(2): Error: cannot have parameter of type void


That page says:

>Code that later used 'x', for example, knows that it is declared as an int64_t, so it doesn't lead to other weird follow on errors that don't make any sense.<

But I don't understand what it means. Maybe this is why this blog post is titled "Clang Error Recovery" instead of "Clang Error Messages".
Later in the same post it says something similar:

>In addition to getting the error message right (and suggesting a fixit replacement to "::"), Clang "knows what you mean" so it handles the subsequent uses of a2 correctly.<

=============================

Clang:

namespace foo {
  struct x { int y; };
}
namespace bar {
  typedef int y;
}
void test() {
  foo::x a;
  bar::y b;
  a + b;
}



t.cc:10:5: error: invalid operands to binary expression ('foo::x' and 'bar::y'
      (aka 'int'))
  a + b;
  ~ ^ ~

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

dmd:

D doesn't have the namespaces, so I have adapted that code like this:


struct foo {
  static struct x { int y; };
}
struct bar {
  typedef int y;
}
void test() {
  foo.x a;
  bar.y b;
  a + b;
}
void main() {}


dmd prints:

temp.d(10): Error: incompatible types for ((a) + (b)): 'x' and 'y'
temp.d(10): Error: + has no effect in expression ((__error) + (__error))

Bye,
bearophile



More information about the Digitalmars-d mailing list