JonasToth added a comment.

Thank you for working on this!

In D71980#1798680 <https://reviews.llvm.org/D71980#1798680>, @njames93 wrote:

> In D71980#1798517 <https://reviews.llvm.org/D71980#1798517>, @lebedev.ri 
> wrote:
>
> > Missing tests; please upload patches with full context (`-U99999`); just 
> > referencing bug# is non-informative - best to say `"[clang-tidy] 
> > check-name: fix 'constexpr if' handling (PR#)"`; possibly you want to split 
> > this up into per-check patches
>
>
> I was thinking as these are all manifestations of the same bug they could go 
> as one patch. As for the test cases, how do you write an effective test when 
> you are dealing with template instantiations given that the code will 
> effectively be checked multiple times for the definition and each 
> instantiation


The bug-reports had cases that reproduced the bugs, you could use those (or 
minimal versions of them).
When you write the templates, you just need to ensure that they are 
instantiated at some point.

  template <typename T>
  T my_sqrt(T val) {
    // This is fake, just to make a templated condition that does not rely on 
the standard library or anything else (tests should not have dependencies in 
LLVM and we do not allow the STL in tests)
    if constexpr (sizeof(T) == 8) {
        return 42.0;
    }
    else {
      return 42.0f;
    }
  }
  
  void instantiate() {
    my_sqrt<double>(10.);
    my_sqrt<float>(10.f);
  }

These should trigger the problem. A test with `if constexpr () ... else if 
constexpr () ...` would be required as well.

To test each of these checks you can use multiple `RUN: ` lines in a single 
test-file. 
You can see 
`clang-tools-extra/test/clang-tidy/checkers/misc-non-private-member-variables-in-classes.cpp`
 for a test that takes heavy advantage from that.
When writing the test please add them to the same directory 
(test/clang-tidy/checkers/<some-check-name>) and follow the same naming 
conventions as those files.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71980/new/

https://reviews.llvm.org/D71980



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to