[cfe-commits] Request feedback for new diagnostic feature - template type diffing

Richard Trieu rtrieu at google.com
Tue Aug 23 21:45:03 PDT 2011


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.

For example:

template <typename T1, typename T2> class A {};
template <typename T1> class B {};
template <typename T1> class C {};
template <typename T1> class D {};

void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}

void bar() {
  foo(A<B<C<D<int> > >, B<C<const double> > >());;
}

would give the error:

type-diff.cc:26:3: error: no matching function for call to 'foo'
  foo(A<B<C<D<int> > >, B<C<const double> > >());;
  ^~~
type-diff.cc:23:6: note: candidate function not viable: no known conversion
from 'A<B<C<D<int> > >, B<C<const double> > >' to
      'A<B<C<D<const int> > >, B<C<D<const double> > > >' for 1st argument;
void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}
     ^

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> > > >'

With template type diffing, additional notes are emitted to show the
difference.  It now becomes:

type-diff.cc:26:3: error: no matching function for call to 'foo'
  foo(A<B<C<D<int> > >, B<C<const double> > >());;
  ^~~
type-diff.cc:23:6: note: candidate function not viable: no known conversion
from 'A<B<C<D<int> > >, B<C<const double> > >' to
      'A<B<C<D<const int> > >, B<C<D<const double> > > >' for 1st argument;
void foo(A<B<C<D<const int> > >, B<C<D<const double> > > > F) {}
     ^
type-diff.cc:23:6: note: Type 'C<const double>' is different from type 'C<D<
>>'
type-diff.cc:23:6: note: Type 'D<int>' is different from type 'D<const int>'

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.

Patch attached and also available at http://codereview.appspot.com/4936048/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110823/504649b0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: template-type-diffing.patch
Type: text/x-patch
Size: 14044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110823/504649b0/attachment.bin>


More information about the cfe-commits mailing list