New issue 1250 by carlosgalvezp: Incorrect include with function template
https://github.com/include-what-you-use/include-what-you-use/issues/1250
Hi,
Consider the following case:
```cpp
// bar.h
#pragma once
#include <iterator>
```
```cpp
// foo.h
#pragma once
#include "bar.h"
template <typename T>
T get_begin(T const(&x)[10])
{
return *std::begin(x);
}
```
```cpp
// foo.cpp
#include "foo.h"
int main()
{
int x[10]{};
return get_begin(x);
}
```
If I run IWYU, on `foo.cpp`, I get:
```
$ include-what-you-use foo.cpp
foo.h should add these lines:
foo.h should remove these lines:
- #include "bar.h" // lines 3-3
The full include-list for foo.h:
---
foo.cpp should add these lines:
#include <iterator> // for begin
foo.cpp should remove these lines:
The full include-list for foo.cpp:
#include "foo.h"
#include <iterator> // for begin
---
```
This is incorrect - `foo.h` should be the one including `iterator`. Currently, if N headers include `foo.h`, they are asked to include `iterator` just because they are calling a function that internally uses something from it. Implementation details are leaked to clients - if `foo.h` no longer needs `iterator`, suddenly all clients need to remove it. This creates a lot of code churn.
This behavior does not happen if the function `get_begin` is a regular (non-template) function.