I have been working on a new feature for diagnostic messages. When a diagnostic contains two template types, give additional notes to show which part of the template is different. For large templates, this will help users more quickly determine what is wrong with the template.<div>
<br></div><div>For example:</div><div><br></div><div><div>template <typename T1, typename T2> class A {};</div><div>template <typename T1> class B {};</div><div>template <typename T1> class C {};</div><div>
template <typename T1> class D {};</div><div><br></div><div>void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}</div><div><br></div><div>void bar() {</div><div>
foo(A<B<C<D<int> > >, B<C<const double> > >());;</div><div>}</div></div><div><br></div><div>would give the error:</div><div><br></div><div><div>type-diff.cc:26:3: error: no matching function for call to 'foo'</div>
<div> foo(A<B<C<D<int> > >, B<C<const double> > >());;</div><div> ^~~</div><div>type-diff.cc:23:6: note: candidate function not viable: no known conversion from 'A<B<C<D<int> > >, B<C<const double> > >' to</div>
<div> 'A<B<C<D<const int> > >, B<C<D<const double> > > >' for 1st argument;</div><div>void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}</div>
<div> ^</div></div><div><br></div><div>It's hard to see exactly what's different from 'A<B<C<D<int> > >, B<C<const double> > >' and 'A<B<C<D<const int> > >, B<C<D<const double> > > >'</div>
<div><br></div><div>With template type diffing, additional notes are emitted to show the difference. It now becomes:</div><div><br></div><div><div>type-diff.cc:26:3: error: no matching function for call to 'foo'</div>
<div> foo(A<B<C<D<int> > >, B<C<const double> > >());;</div><div> ^~~</div><div>type-diff.cc:23:6: note: candidate function not viable: no known conversion from 'A<B<C<D<int> > >, B<C<const double> > >' to</div>
<div> 'A<B<C<D<const int> > >, B<C<D<const double> > > >' for 1st argument;</div><div>void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}</div>
<div> ^</div><div>type-diff.cc:23:6: note: Type 'C<const double>' is different from type 'C<D< >>'</div><div>type-diff.cc:23:6: note: Type 'D<int>' is different from type 'D<const int>'</div>
</div><div><br></div><div>I have attached a patch with an early prototype of this feature and would appreciate any feedback. Currently, the extra notes are only displayed for this one note, but should be easy enough to extend to other places. There's also a test case included to show some other examples of this feature. Let me know what you think about it.</div>
<div><br></div><div>Patch attached and also available at <a href="http://codereview.appspot.com/4936048/">http://codereview.appspot.com/4936048/</a></div>