blob: 00a3f9a9f689c6513dcd179e5ce0c3cbe3ee9ea1 [file] [log] [blame]
Chris Lattner76766012009-03-19 18:52:17 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
Douglas Gregord89df5a2011-06-01 22:45:49 +00005 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
Chris Lattner76766012009-03-19 18:52:17 +00006 <title>Clang - Expressive Diagnostics</title>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +00007 <link type="text/css" rel="stylesheet" href="menu.css">
8 <link type="text/css" rel="stylesheet" href="content.css">
Chris Lattner76766012009-03-19 18:52:17 +00009 <style type="text/css">
Stephen Hines651f13c2014-04-23 16:59:28 -070010 .loc { font-weight: bold; }
11 .err { color:red; font-weight: bold; }
12 .warn { color:magenta; font-weight: bold; }
13 .note { color:gray; font-weight: bold; }
14 .msg { font-weight: bold; }
15 .cmd { font-style: italic; }
16 .snip { }
17 .point { color:green; font-weight: bold; }
Benjamin Kramer665a8dc2012-01-15 15:26:07 +000018 </style>
Chris Lattner76766012009-03-19 18:52:17 +000019</head>
20<body>
21
22<!--#include virtual="menu.html.incl"-->
23
24<div id="content">
25
26
27<!--=======================================================================-->
28<h1>Expressive Diagnostics</h1>
29<!--=======================================================================-->
30
31<p>In addition to being fast and functional, we aim to make Clang extremely user
32friendly. As far as a command-line compiler goes, this basically boils down to
33making the diagnostics (error and warning messages) generated by the compiler
34be as useful as possible. There are several ways that we do this. This section
35talks about the experience provided by the command line compiler, contrasting
Stephen Hines651f13c2014-04-23 16:59:28 -070036Clang output to GCC 4.9's output in some cases.
Chris Lattner76766012009-03-19 18:52:17 +000037</p>
38
39<h2>Column Numbers and Caret Diagnostics</h2>
40
41<p>First, all diagnostics produced by clang include full column number
Douglas Gregord89df5a2011-06-01 22:45:49 +000042information. The clang command-line compiler driver uses this information
Benjamin Kramer665a8dc2012-01-15 15:26:07 +000043to print "point diagnostics".
Douglas Gregord89df5a2011-06-01 22:45:49 +000044(IDEs can use the information to display in-line error markup.)
Stephen Hines651f13c2014-04-23 16:59:28 -070045This is nice because it makes it very easy to understand exactly
46what is wrong in a particular piece of code.</p>
Douglas Gregord89df5a2011-06-01 22:45:49 +000047
Stephen Hines651f13c2014-04-23 16:59:28 -070048<p>The point (the green "^" character) exactly shows where the problem is, even
Douglas Gregord89df5a2011-06-01 22:45:49 +000049inside of a string. This makes it really easy to jump to the problem and
Stephen Hines651f13c2014-04-23 16:59:28 -070050helps when multiple instances of the same character occur on a line. (We'll
Douglas Gregord89df5a2011-06-01 22:45:49 +000051revisit this more in following examples.)</p>
Chris Lattner76766012009-03-19 18:52:17 +000052
53<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -070054 $ <span class="cmd">gcc-4.9 -fsyntax-only -Wformat format-strings.c</span>
55 format-strings.c: In function 'void f()':
56 format-strings.c:91:16: warning: field precision specifier '.*' expects a matching 'int' argument [-Wformat=]
57 printf("%.*d");
58 ^
59 format-strings.c:91:16: warning: format '%d' expects a matching 'int' argument [-Wformat=]
60 $ <span class="cmd">clang -fsyntax-only format-strings.c</span>
61 <span class="loc">format-strings.c:91:13:</span> <span class="warn">warning:</span> <span class="msg">'.*' specified field precision is missing a matching 'int' argument</span>
62 <span class="snip" > printf("%.*d");</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +000063 <span class="point"> ^</span>
Chris Lattner76766012009-03-19 18:52:17 +000064</pre>
65
Stephen Hines651f13c2014-04-23 16:59:28 -070066<p>Note that modern versions of GCC have followed Clang's lead, and are
67now able to give a column for a diagnostic, and include a snippet of source
68text in the result. However, Clang's column number is much more accurate,
69pointing at the problematic format specifier, rather than the <tt>)</tt>
70character the parser had reached when the problem was detected.
71Also, Clang's diagnostic is colored by default, making it easier to
72distinguish from nearby text.</p>
73
Chris Lattner76766012009-03-19 18:52:17 +000074<h2>Range Highlighting for Related Text</h2>
75
76<p>Clang captures and accurately tracks range information for expressions,
77statements, and other constructs in your program and uses this to make
Douglas Gregord89df5a2011-06-01 22:45:49 +000078diagnostics highlight related information. In the following somewhat
79nonsensical example you can see that you don't even need to see the original source code to
80understand what is wrong based on the Clang error. Because clang prints a
Benjamin Kramer665a8dc2012-01-15 15:26:07 +000081point, you know exactly <em>which</em> plus it is complaining about. The range
Douglas Gregord89df5a2011-06-01 22:45:49 +000082information highlights the left and right side of the plus which makes it
83immediately obvious what the compiler is talking about.
84Range information is very useful for
85cases involving precedence issues and many other cases.</p>
Chris Lattner76766012009-03-19 18:52:17 +000086
87<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -070088 $ <span class="cmd">gcc-4.9 -fsyntax-only t.c</span>
89 t.c: In function 'int f(int, int)':
90 t.c:7:39: error: invalid operands to binary + (have 'int' and 'struct A')
91 return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);
92 ^
93 $ <span class="cmd">clang -fsyntax-only t.c</span>
94 <span class="loc">t.c:7:39:</span> <span class="err">error:</span> <span class="msg">invalid operands to binary expression ('int' and 'struct A')</span>
95 <span class="snip" > return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X);</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +000096 <span class="point"> ~~~~~~~~~~~~~~ ^ ~~~~~</span>
Chris Lattner76766012009-03-19 18:52:17 +000097</pre>
98
Chris Lattner76766012009-03-19 18:52:17 +000099<h2>Precision in Wording</h2>
100
101<p>A detail is that we have tried really hard to make the diagnostics that come
102out of clang contain exactly the pertinent information about what is wrong and
103why. In the example above, we tell you what the inferred types are for
104the left and right hand sides, and we don't repeat what is obvious from the
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000105point (e.g., that this is a "binary +").</p>
Douglas Gregord89df5a2011-06-01 22:45:49 +0000106
Stephen Hines651f13c2014-04-23 16:59:28 -0700107<p>Many other examples abound. In the following example, not only do we tell you
108that there is a problem with the <tt>*</tt>
Douglas Gregord89df5a2011-06-01 22:45:49 +0000109and point to it, we say exactly why and tell you what the type is (in case it is
110a complicated subexpression, such as a call to an overloaded function). This
111sort of attention to detail makes it much easier to understand and fix problems
112quickly.</p>
Chris Lattner76766012009-03-19 18:52:17 +0000113
114<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700115 $ <span class="cmd">gcc-4.9 -fsyntax-only t.c</span>
116 t.c:5:11: error: invalid type argument of unary '*' (have 'int')
117 return *SomeA.X;
118 ^
119 $ <span class="cmd">clang -fsyntax-only t.c</span>
120 <span class="loc">t.c:5:11:</span> <span class="err">error:</span> <span class="msg">indirection requires pointer operand ('int' invalid)</span>
121 <span class="snip" > int y = *SomeA.X;</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000122 <span class="point"> ^~~~~~~~</span>
Chris Lattner76766012009-03-19 18:52:17 +0000123</pre>
124
Chris Lattner76766012009-03-19 18:52:17 +0000125<h2>Typedef Preservation and Selective Unwrapping</h2>
126
127<p>Many programmers use high-level user defined types, typedefs, and other
128syntactic sugar to refer to types in their program. This is useful because they
129can abbreviate otherwise very long types and it is useful to preserve the
130typename in diagnostics. However, sometimes very simple typedefs can wrap
131trivial types and it is important to strip off the typedef to understand what
132is going on. Clang aims to handle both cases well.<p>
133
Douglas Gregord89df5a2011-06-01 22:45:49 +0000134<p>The following example shows where it is important to preserve
Stephen Hines651f13c2014-04-23 16:59:28 -0700135a typedef in C.</p>
Chris Lattner76766012009-03-19 18:52:17 +0000136
137<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700138 $ <span class="cmd">clang -fsyntax-only t.c</span>
139 <span class="loc">t.c:15:11:</span> <span class="err">error:</span> <span class="msg">can't convert between vector values of different size ('__m128' and 'int const *')</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000140 <span class="snip"> myvec[1]/P;</span>
141 <span class="point"> ~~~~~~~~^~</span>
Chris Lattner76766012009-03-19 18:52:17 +0000142</pre>
143
Douglas Gregord89df5a2011-06-01 22:45:49 +0000144<p>The following example shows where it is useful for the compiler to expose
145underlying details of a typedef. If the user was somehow confused about how the
146system "pid_t" typedef is defined, Clang helpfully displays it with "aka".</p>
Chris Lattner76766012009-03-19 18:52:17 +0000147
148<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700149 $ <span class="cmd">clang -fsyntax-only t.c</span>
150 <span class="loc">t.c:13:9:</span> <span class="err">error:</span> <span class="msg">member reference base type 'pid_t' (aka 'int') is not a structure or union</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000151 <span class="snip"> myvar = myvar.x;</span>
152 <span class="point"> ~~~~~ ^</span>
Chris Lattner76766012009-03-19 18:52:17 +0000153</pre>
154
Douglas Gregor969c6892009-04-01 15:47:24 +0000155<p>In C++, type preservation includes retaining any qualification written into type names. For example, if we take a small snippet of code such as:
156
157<blockquote>
158<pre>
159namespace services {
160 struct WebService { };
161}
162namespace myapp {
163 namespace servers {
164 struct Server { };
165 }
166}
167
168using namespace myapp;
Benjamin Kramerd8ee4072011-08-06 03:04:45 +0000169void addHTTPService(servers::Server const &amp;server, ::services::WebService const *http) {
Douglas Gregor969c6892009-04-01 15:47:24 +0000170 server += http;
171}
172</pre>
173</blockquote>
174
Stephen Hines651f13c2014-04-23 16:59:28 -0700175<p>and then compile it, we see that Clang is both providing accurate information and is retaining the types as written by the user (e.g., "servers::Server", "::services::WebService"):
Douglas Gregor969c6892009-04-01 15:47:24 +0000176
177<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700178 $ <span class="cmd">clang -fsyntax-only t.cpp</span>
179 <span class="loc">t.cpp:9:10:</span> <span class="err">error:</span> <span class="msg">invalid operands to binary expression ('servers::Server const' and '::services::WebService const *')</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000180 <span class="snip">server += http;</span>
181 <span class="point">~~~~~~ ^ ~~~~</span>
Douglas Gregor969c6892009-04-01 15:47:24 +0000182</pre>
183
184<p>Naturally, type preservation extends to uses of templates, and Clang retains information about how a particular template specialization (like <code>std::vector&lt;Real&gt;</code>) was spelled within the source code. For example:</p>
185
186<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700187 $ <span class="cmd">clang -fsyntax-only t.cpp</span>
188 <span class="loc">t.cpp:12:7:</span> <span class="err">error:</span> <span class="msg">incompatible type assigning 'vector&lt;Real&gt;', expected 'std::string' (aka 'class std::basic_string&lt;char&gt;')</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000189 <span class="snip">str = vec</span>;
190 <span class="point">^ ~~~</span>
Douglas Gregor969c6892009-04-01 15:47:24 +0000191</pre>
192
Chris Lattner76766012009-03-19 18:52:17 +0000193<h2>Fix-it Hints</h2>
194
Douglas Gregoreff49c62009-04-01 16:24:40 +0000195<p>"Fix-it" hints provide advice for fixing small, localized problems
196in source code. When Clang produces a diagnostic about a particular
197problem that it can work around (e.g., non-standard or redundant
198syntax, missing keywords, common mistakes, etc.), it may also provide
199specific guidance in the form of a code transformation to correct the
Douglas Gregord89df5a2011-06-01 22:45:49 +0000200problem. In the following example, Clang warns about the use of a GCC
201extension that has been considered obsolete since 1993. The underlined
202code should be removed, then replaced with the code below the
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000203point line (".x =" or ".y =", respectively).</p>
Chris Lattner76766012009-03-19 18:52:17 +0000204
Douglas Gregoreff49c62009-04-01 16:24:40 +0000205<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700206 $ <span class="cmd">clang t.c</span>
207 <span class="loc">t.c:5:28:</span> <span class="warn">warning:</span> <span class="msg">use of GNU old-style field designator extension</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000208 <span class="snip">struct point origin = { x: 0.0, y: 0.0 };</span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700209 <span class="err">~~</span> <span class="msg"><span class="point">^</span></span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000210 <span class="snip">.x = </span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700211 <span class="loc">t.c:5:36:</span> <span class="warn">warning:</span> <span class="msg">use of GNU old-style field designator extension</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000212 <span class="snip">struct point origin = { x: 0.0, y: 0.0 };</span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700213 <span class="err">~~</span> <span class="msg"><span class="point">^</span></span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000214 <span class="snip">.y = </span>
Douglas Gregoreff49c62009-04-01 16:24:40 +0000215</pre>
216
Douglas Gregord89df5a2011-06-01 22:45:49 +0000217<p>"Fix-it" hints are most useful for
Chris Lattner0e3b44b2009-09-30 20:19:10 +0000218working around common user errors and misconceptions. For example, C++ users
219commonly forget the syntax for explicit specialization of class templates,
Douglas Gregord89df5a2011-06-01 22:45:49 +0000220as in the error in the following example. Again, after describing the problem,
221Clang provides the fix--add <code>template&lt;&gt;</code>--as part of the
222diagnostic.<p>
Douglas Gregoreff49c62009-04-01 16:24:40 +0000223
224<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700225 $ <span class="cmd">clang t.cpp</span>
226 <span class="loc">t.cpp:9:3:</span> <span class="err">error:</span> <span class="msg">template specialization requires 'template&lt;&gt;'</span>
Douglas Gregoreff49c62009-04-01 16:24:40 +0000227 struct iterator_traits&lt;file_iterator&gt; {
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000228 <span class="point">^</span>
229 <span class="snip">template&lt;&gt; </span>
Douglas Gregoreff49c62009-04-01 16:24:40 +0000230</pre>
231
Richard Trieue59331a2012-06-27 02:00:20 +0000232<h2>Template Type Diffing</h2>
233
234<p>Templates types can be long and difficult to read. Moreso when part of an
235error message. Instead of just printing out the type name, Clang has enough
236information to remove the common elements and highlight the differences. To
237show the template structure more clearly, the templated type can also be
238printed as an indented text tree.</p>
239
240Default: template diff with type elision
241<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700242<span class="loc">t.cc:4:5:</span> <span class="note">note:</span> candidate function not viable: no known conversion from 'vector&lt;map&lt;[...], <span class="template-highlight">float</span>&gt;&gt;' to 'vector&lt;map&lt;[...], <span class="template-highlight">double</span>&gt;&gt;' for 1st argument;
Richard Trieue59331a2012-06-27 02:00:20 +0000243</pre>
244-fno-elide-type: template diff without elision
245<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700246<span class="loc">t.cc:4:5:</span> <span class="note">note:</span> candidate function not viable: no known conversion from 'vector&lt;map&lt;int, <span class="template-highlight">float</span>&gt;&gt;' to 'vector&lt;map&lt;int, <span class="template-highlight">double</span>&gt;&gt;' for 1st argument;
Richard Trieue59331a2012-06-27 02:00:20 +0000247</pre>
248-fdiagnostics-show-template-tree: template tree printing with elision
249<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700250<span class="loc">t.cc:4:5:</span> <span class="note">note:</span> candidate function not viable: no known conversion for 1st argument;
Richard Trieue59331a2012-06-27 02:00:20 +0000251 vector&lt;
252 map&lt;
253 [...],
254 [<span class="template-highlight">float</span> != <span class="template-highlight">double</span>]&gt;&gt;
255</pre>
256-fdiagnostics-show-template-tree -fno-elide-type: template tree printing with no elision
257<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700258<span class="loc">t.cc:4:5:</span> <span class="note">note:</span> candidate function not viable: no known conversion for 1st argument;
Richard Trieue59331a2012-06-27 02:00:20 +0000259 vector&lt;
260 map&lt;
261 int,
262 [<span class="template-highlight">float</span> != <span class="template-highlight">double</span>]&gt;&gt;
263</pre>
264
Chris Lattner76766012009-03-19 18:52:17 +0000265<h2>Automatic Macro Expansion</h2>
266
267<p>Many errors happen in macros that are sometimes deeply nested. With
268traditional compilers, you need to dig deep into the definition of the macro to
Douglas Gregord89df5a2011-06-01 22:45:49 +0000269understand how you got into trouble. The following simple example shows how
270Clang helps you out by automatically printing instantiation information and
271nested range information for diagnostics as they are instantiated through macros
272and also shows how some of the other pieces work in a bigger example.</p>
Chris Lattner76766012009-03-19 18:52:17 +0000273
274<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700275 $ <span class="cmd">clang -fsyntax-only t.c</span>
276 <span class="loc">t.c:80:3:</span> <span class="err">error:</span> <span class="msg">invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000277 <span class="snip"> X = MYMAX(P, F);</span>
278 <span class="point"> ^~~~~~~~~~~</span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700279 <span class="loc">t.c:76:94:</span> <span class="note">note:</span> expanded from:
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000280 <span class="snip">#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a &lt; __b ? __b : __a; })</span>
281 <span class="point"> ~~~ ^ ~~~</span>
Chris Lattner76766012009-03-19 18:52:17 +0000282</pre>
283
Douglas Gregord89df5a2011-06-01 22:45:49 +0000284<p>Here's another real world warning that occurs in the "window" Unix package (which
Chris Lattner76766012009-03-19 18:52:17 +0000285implements the "wwopen" class of APIs):</p>
286
287<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700288 $ <span class="cmd">clang -fsyntax-only t.c</span>
289 <span class="loc">t.c:22:2:</span> <span class="warn">warning:</span> <span class="msg">type specifier missing, defaults to 'int'</span>
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000290 <span class="snip"> ILPAD();</span>
291 <span class="point"> ^</span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700292 <span class="loc">t.c:17:17:</span> <span class="note">note:</span> expanded from:
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000293 <span class="snip">#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */</span>
294 <span class="point"> ^</span>
Stephen Hines651f13c2014-04-23 16:59:28 -0700295 <span class="loc">t.c:14:2:</span> <span class="note">note:</span> expanded from:
Benjamin Kramer665a8dc2012-01-15 15:26:07 +0000296 <span class="snip"> register i; \</span>
297 <span class="point"> ^</span>
Chris Lattner76766012009-03-19 18:52:17 +0000298</pre>
299
Douglas Gregord89df5a2011-06-01 22:45:49 +0000300<p>In practice, we've found that Clang's treatment of macros is actually more useful in multiply nested
Chris Lattner76766012009-03-19 18:52:17 +0000301macros that in simple ones.</p>
302
Chris Lattner0e3b44b2009-09-30 20:19:10 +0000303<h2>Quality of Implementation and Attention to Detail</h2>
304
305<p>Finally, we have put a lot of work polishing the little things, because
Douglas Gregord89df5a2011-06-01 22:45:49 +0000306little things add up over time and contribute to a great user experience.</p>
307
Douglas Gregord89df5a2011-06-01 22:45:49 +0000308<p>The following example shows that we recover from the simple case of
309forgetting a ; after a struct definition much better than GCC.</p>
Chris Lattner0e3b44b2009-09-30 20:19:10 +0000310
Chris Lattner94634cc2010-02-02 01:35:23 +0000311<pre>
Stephen Hines651f13c2014-04-23 16:59:28 -0700312 $ <span class="cmd">cat t.cc</span>
Chris Lattner94634cc2010-02-02 01:35:23 +0000313 template&lt;class T&gt;
Stephen Hines651f13c2014-04-23 16:59:28 -0700314 class a {};
315 struct b {}
316 a&lt;int&gt; c;
317 $ <span class="cmd">gcc-4.9 t.cc</span>
318 t.cc:4:8: error: invalid declarator before 'c'
319 a&lt;int&gt; c;
320 ^
321 $ <span class="cmd">clang t.cc</span>
322 <span class="loc">t.cc:3:12:</span> <span class="err">error:</span> <span class="msg">expected ';' after struct</span>
323 <span class="snip" >struct b {}</span>
324 <span class="point"> ^</span>
325 <span class="point"> ;</span>
Chris Lattner94634cc2010-02-02 01:35:23 +0000326</pre>
327
Stephen Hines651f13c2014-04-23 16:59:28 -0700328<p>The following example shows that we diagnose and recover from a missing
329<tt>typename</tt> keyword well, even in complex circumstances where GCC
330cannot cope.</p>
331
332<pre>
333 $ <span class="cmd">cat t.cc</span>
334 template&lt;class T&gt; void f(T::type) { }
335 struct A { };
336 void g()
337 {
338 A a;
339 f&lt;A&gt;(a);
340 }
341 $ <span class="cmd">gcc-4.9 t.cc</span>
342 t.cc:1:33: error: variable or field 'f' declared void
343 template&lt;class T&gt; void f(T::type) { }
344 ^
345 t.cc: In function 'void g()':
346 t.cc:6:5: error: 'f' was not declared in this scope
347 f&lt;A&gt;(a);
348 ^
349 t.cc:6:8: error: expected primary-expression before '>' token
350 f&lt;A&gt;(a);
351 ^
352 $ <span class="cmd">clang t.cc</span>
353 <span class="loc">t.cc:1:26:</span> <span class="err">error:</span> <span class="msg">missing 'typename' prior to dependent type name 'T::type'</span>
354 <span class="snip" >template&lt;class T&gt; void f(T::type) { }</span>
355 <span class="point"> ^~~~~~~</span>
356 <span class="point"> typename </span>
357 <span class="loc">t.cc:6:5:</span> <span class="err">error:</span> <span class="msg">no matching function for call to 'f'</span>
358 <span class="snip" > f&lt;A&gt;(a);</span>
359 <span class="point"> ^~~~</span>
360 <span class="loc">t.cc:1:24:</span> <span class="note">note:</span> <span class="msg">candidate template ignored: substitution failure [with T = A]: no type named 'type' in 'A'</span>
361 <span class="snip" >template&lt;class T&gt; void f(T::type) { }</span>
362 <span class="point"> ^ ~~~~</span>
363</pre>
364
365
366
Chris Lattner0e3b44b2009-09-30 20:19:10 +0000367<p>While each of these details is minor, we feel that they all add up to provide
368a much more polished experience.</p>
369
Chris Lattner76766012009-03-19 18:52:17 +0000370</div>
371</body>
372</html>