[PATCH] D50619: [clang-tidy] Handle unresolved expressions in ExprMutationAnalyzer

Shuai Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 15 17:41:41 PDT 2018


shuaiwang added inline comments.


================
Comment at: unittests/clang-tidy/ExprMutationAnalyzerTest.cpp:309
 
+TEST(ExprMutationAnalyzerTest, CallUnresolved) {
+  auto AST =
----------------
JonasToth wrote:
> I think we are missing tests for non-type template paramters (`template <size_t N>`). They should behave the same. But the following case would not be a mutation:
> 
> ```
> void non_mutating(const char* Array, int size) { /* Foo */ }
> template <int N>
> struct ArrayLike {
>   char* data[N]; // Initialized to something
>   void SomeFunction() {
>     non_mutating(data, N);
>   }
> };
> ```
> 
> The difference between the 'normal' and non-type templates would be, that `N` is not mutatable at all and the semantics is clear (builtin integer-like type).
> 
> If the current implementation would not figure that out, you can just add a test for it and assume a mutation. Handling non-type templates later is absolutly ok.
We have to assume `data` is mutated here as well. I'll add a test case for this.

```
void g(const char*, int); // <-- doesn't mutate
void g(char(&)[8], int); // <-- do mutate

template <int N>
void f() {
    char data[N];
    g(data, N); // <-- we don't know which `g` will be called yet
}

void h() {
    f<8>(); // <-- f calls g(char(&)[8], int) internally
    f<9>(); // <-- f calls g(const char*, int) internally
}
```




Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D50619





More information about the cfe-commits mailing list