Clang Template Error Messages
Contents |
Control Error and Warning Messages Formatting of Diagnostics Individual Warning Groups Options to Control Clang Crash Diagnostics Options to Emit Optimization Reports Current limitations Other Options Language and Target-Independent Features Controlling Errors and
Clang Vs Gcc Error Messages
Warnings Controlling How Clang Displays Diagnostics Diagnostic Mappings Diagnostic Categories Controlling Diagnostics via word template error messages Command Line Flags Controlling Diagnostics via Pragmas Controlling Diagnostics in System Headers Enabling All Diagnostics Controlling Static Analyzer Diagnostics clang warning list Precompiled Headers Generating a PCH File Using a PCH File Relocatable PCH Files Controlling Code Generation Profile Guided Optimization Differences Between Sampling and Instrumentation Using Sampling Profilers Sample Profile Formats Sample Profile
Clang Optimization Flags
Text Format Profiling with Instrumentation Disabling Instrumentation Controlling Debug Information Controlling Size of Debug Information Controlling Debugger "Tuning" Comment Parsing Options C Language Features Extensions supported by clang Differences between various standard modes GCC extensions not implemented yet Intentionally unsupported GCC extensions Microsoft extensions C++ Language Features Controlling implementation limits Objective-C Language Features Objective-C++ Language Features OpenMP Features Controlling implementation limits Target-Specific Features
Clang-cl
and Limitations CPU Architectures Features and Limitations X86 ARM PowerPC Other platforms Operating System Features and Limitations Darwin (Mac OS X) Windows Cygwin MinGW32 MinGW-w64 clang-cl Command-Line Options The /fallback Option Introduction¶ The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets. For more general information, please see the Clang Web Site or the LLVM Web Site. This document describes important notes about using Clang as a compiler for an end-user, documenting the supported features, command line options, etc. If you are interested in using Clang to build a tool that processes code, please see "Clang" CFE Internals Manual. If you are interested in the Clang Static Analyzer, please see its web page. Clang is designed to support the C family of programming languages, which includes C, Objective-C, C++, and Objective-C++ as well as many dialects of those. For language-specific information, please see the corresponding language specific section: C Language: K&R
debate flamed up again. I thought I would deliver my few cents too. It is claimed from time to time that clang has more helpful error messages. It is, in my opinion, a clain that is just plain wrong. They both stink. clang ast dump Let's look at a few samples:
static int foo (int a, int b)
Clang Tutorial
{ return a + b; } here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn http://programmers.stackexchange.com/questions/70086/why-are-c-template-error-messages-so-horrific more about Stack Overflow the company Business Learn more about hiring developers or http://stackoverflow.com/questions/8779521/tools-to-generate-higher-quality-error-messages-for-template-based-code posting ads with us Programmers Questions Tags Users Badges Unanswered Ask Question _ Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The error messages best answers are voted up and rise to the top Why are C++ template error messages so horrific? up vote 14 down vote favorite 4 C++ templates are notorious for generating long, unreadable error messages. I have a general idea of why template error messages in C++ are so bad. Essentially, the problem is that the error isn't triggered until the compiler encounters syntax that is not template error messages supported by a certain type in a template. For example: template here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Tools to generate higher-quality error messages for template-based code? up vote 28 down vote favorite 7 Concepts, that would render these tools unnecessary, are not part of C++11. STLFilt would have been one option but it is no longer maintained. Clang claims to give expressive diagnostics although important C++11 features are not available yet. colorgcc seems to be abandoned since 1999. What production quality tools are available to decipher error messages stemming from template-based code? Eclipse-CDT support would be nice too. :) If I give up on C++11, what options do I have for C++98? Related questions: Deciphering C++ template error messages Improving g++ output c++ templates stl c++11 custom-errors share|improve this question edited Jan 3 '15 at 22:22 Jack 90k20141250 asked Jan 8 '12 at 17:18 Ali 29.3k11102162 1 Which C++11 features are you specifically requiring that clang doesn't have yet? –Ben Voigt Jan 8 '12 at 17:40 1 @BenVoigt According to the Clang website Initializer lists, New wording for C++0x lambdas, Inheriting constructors, Universal character name literal, User-defined literals are not available. Does Clang indeed provide better error messages for templates? I have never tried it. –Ali Jan 8 '12 at 18:02 1 @Lightness One of the main selling points of Concepts was always better error messages - eg "Foo is not CopyConstructible because ..." rather than an obscure error deep inside the library implementation. –Alan Stokes Jan 8 '12 at 19:05 1 @AlanStokes: Wh
int bar (int a) { return foo (a (4 + 1) * 2); }
gcc says clang++ (excerpts):
e1.c:2:33: error: called object ‘a’ is not a function or function pointer
e1.c:2:1: error: too few arguments to function ‘foo’
clang says (excerpts):
e1.c:2:33: error: called object type 'int' is not a function http://clang.llvm.org/docs/UsersManual.html or function pointer
The best thing you can say about the error messages here is that they at least point you to the right location. gcc is a tad better by virtue of printing the second error message which at least hints of the real problem, but neither compiler tell us what the problem is: "missing comma". It looks like clang is suppressing the second and further errors on a line. Note, however, that in this case it has https://blogs.gnome.org/mortenw/2014/01/27/gcc-vs-clang-for-error-messages/ suppressed the more informative error. Moving on with a missing opening parenthesis:
static int foo (int a, int b) { return a + b; }
int bar (int a) { return foo a); }
From gcc we get the wisdom
e2.c:2:19: warning: return makes integer from pointer without a cast [enabled by default]
e2.c:2:30: error: expected ‘;’ before ‘a’
e2.c:2:31: error: expected statement before ‘)’ token
while clang produces
e2.c:2:26: warning: incompatible pointer to integer conversion returning
'int (int, int)' from a function with result type 'int' [-Wint-conversion]
e2.c:2:29: error: expected ';' after return statement
I don't see that one set of utter nonsense is better than the other and spending time colour coding the output shows a dubious set of priorities. Clang would do well to add hyphens to "pointer to integer". How about this?
#include
#define EMIT(c) fprintf(stderr,"%c",(c))
Nothing from gcc, nothing from clang, nothing from sparse. Yet it's a clear violation of C99's paragraph 7.26.3. C++ doesn't fare any better:
#include
std::vector
gcc delivers 67 lines of nonsense starting with
/usr/include/c++/4.8/ext/alloc_traits.h:199:53: error: ‘int’ is not a class, str
uct, or union type
typedef typename _Alloc::pointer pointer;
whereas clang emits 87 lines of garbage starting with
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ext/alloc_traits.h