[PATCH] D11784: [PATCH] clang-tidy check for incorrect move constructor initializers

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 14 05:25:39 PDT 2015


aaron.ballman added a comment.

In http://reviews.llvm.org/D11784#224430, @alexfh wrote:

> In http://reviews.llvm.org/D11784#224421, @aaron.ballman wrote:
>
> > In http://reviews.llvm.org/D11784#224386, @alexfh wrote:
> >
> > > > One thing I am not certain of in this patch is how to test it. I have some rudimentary tests, but am unable to test the "note:" diagnostics from 
> > >
> > > >  FileCheck (attempting to add any cause the "warning:" diagnostics to not be found).
> > >
> > >
> > > Can you give an example of what you do and what results do you get?
> >
> >
> > I put "CHECK: :[[@LINE+1]]:3: note: copy constructor being called" into the source file, and tests no longer pass because it cannot find the matching "warning: " diagnostic. If I then remove the warning diagnostic, the tests pass again. So it seems I can test one or the other, but not both. Specifically (with note and warning):
>
>
> Might it be that you got the line offsets in @LINE incorrectly? A test like this should work, if both the warning and the note are on the same line:
>
>   // CHECK: :[[@LINE+2]]:...: warning: ....
>   // CHECK: :[[@LINE+1]]:...: note: ....
>   some_line_that_generates_a_warning_with_a_note();


The warning is on line 28, the note is on line 20.

> If your note is generated on a different line than the warning (e.g. class declaration vs. the incorrect use of a variable), then you may have to use @LINE+x for the warning and the line number verbatim for the note check.


Ah, interesting -- I was avoiding that because of how fragile it is. Also, it seems to require me grouping the CHECK lines together. e.g.) this fails:

struct B {

  B() {}
  B(const B&) {}
  B(B &&) {}   // CHECK: 19:3: note: copy constructor being called

};

struct D : B {

  D() : B() {}
  D(const D &RHS) : B(RHS) {}
  // CHECK: :[[@LINE+1]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-base]
  D(D &&RHS) : B(RHS) {}

};

But this succeeds:

struct B {

  B() {}
  B(const B&) {}
  B(B &&) {}

};

struct D : B {

  D() : B() {}
  D(const D &RHS) : B(RHS) {}
  // CHECK: :[[@LINE+2]]:16: warning: move constructor initializes base class by calling a copy constructor [misc-move-constructor-base]
  // CHECK: 19:3: note: copy constructor being called
  D(D &&RHS) : B(RHS) {}

};

In any event, there's now a solution that lets me test the notes, so that's great. Thank you!

~Aaron


http://reviews.llvm.org/D11784





More information about the cfe-commits mailing list