Issue 927 in include-what-you-use: False positive <type_traits> for enable_if_t and remove_reference<>::type

1 view
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Jun 2, 2021, 1:59:25 AMJun 2
to include-wh...@googlegroups.com
New issue 927 by ptomato: False positive <type_traits> for enable_if_t and remove_reference<>::type
https://github.com/include-what-you-use/include-what-you-use/issues/927

In two cases I get false positives of `<type_traits>` for files that don't use it. Here are minimal examples of both cases. In both cases, it seems to be the header file that's at fault; any implementation file that includes it will get the false positive.

## Example 1

**a.cpp**:
```c++
#include "b.h"

enum class F {
VAL = 1,
};

struct A {
F a;

bool method() {
return a & F::VAL;
}
};
```

**b.h**:
```c++
#pragma once
#include <type_traits>

struct B {
operator bool() { return true; }
};

template <class E>
std::enable_if_t<true, B> operator&(E const&, E const&) {
return B();
}
```

Command line:
```
$ include-what-you-use a.cpp

a.cpp should add these lines:
#include <type_traits> // for enable_if_t

a.cpp should remove these lines:

The full include-list for a.cpp:
#include <type_traits> // for enable_if_t
#include "b.h" // for operator&
---
```

## Example 2

**a.cpp**:
```c++
#include "b.h"

char a() {
B<char> b;
return b.b()[0];
}
```

**b.h**:
```c++
#pragma once
#include <type_traits>

template <typename T>
struct B {
std::add_pointer_t<T> b();
};
```

Command line:
```
$ include-what-you-use a.cpp

a.cpp should add these lines:
#include <type_traits> // for remove_reference<>::type

a.cpp should remove these lines:

The full include-list for a.cpp:
#include <type_traits> // for remove_reference<>::type
#include "b.h" // for B
---
```

Reply all
Reply to author
Forward
0 new messages