I finally got around to reading up on the clang compiler and I love it. The error messages are so helpful. Here’s a quick example with a syntax error. Lets compile it on the command line.

#include <iostream>
int main() {
	std::cotut << "Hello World";
	return 0;
}


What happens when I run the code with g++?

paulsolt@~/dev $ g++ test.cpp
test.cpp: In function ‘int main()’:
test.cpp:3: error: ‘cotut’ is not a member of ‘std’

Here’s what happens in clang++, notice how it highlights the position and it’s actually more helpful in fixing the error.

paulsolt@~/dev $ clang++ test.cpp
test.cpp:4:7: error: no member named 'cotut' in namespace 'std'; did you mean 'cout'?
        std::cotut << "Hello World";
        ~~~~~^~~~~
             cout
/usr/include/c++/4.2.1/iostream:63:18: note: 'cout' declared here
  extern ostream cout;          ///< Linked to standard output
Tagged with:
 

2 Responses to clang++ is awesome, goodbye g++

  1. Joan says:

    Looks good! How do we install clang++?

  2. Paul Solt says:

    It’s in the upcoming editor from Apple. See the open source site: http://clang.llvm.org/

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>