# clang-tidy does not find include \`\<iostream\>\` with \`\_\_run\_co\_compile\`

**URL:** https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910
**Category:** Code
**Tags:** os:linux
**Created:** [June 22, 2022, 5:11pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910 "2022-06-22T17:11:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![gabyx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gabyx/32/2107_2.png) [@gabyx](https://discourse.cmake.org/u/gabyx)
#### Post date: [June 22, 2022, 5:11pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/1 "2022-06-22T17:11:44Z")

</div>

I am wondering why `clang-tidy` does not find includes with `libc++` but does with `libstdc++` when configured  
with `CXX_CLANG_TIDY=clang-tidy`:

The compile command which **works** with `linux-clang-libstc++-debug` is:

```nohighlight
/usr/local/bin/cmake \
-E \
__run_co_compile \
--launcher=/usr/bin/ccache \
--tidy="/usr/bin/clang-tidy;-header-filter=.;-extra-arg=-Wno-unknown-warning-option;-checks=-clang-diagnostic-unused-command-line-argument;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" \
--source=/workspaces/cmake-general/tests/project/build/linux-clang-libstdc++-debug/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.cxx \
-- \
/usr/bin/clang++-13 \
-DCARES_STATICLIB \
-DFMT_SHARED \
-D_GLIBCXX_USE_CXX11_ABI=1 \
-I/workspaces/cmake-general/tests/project/src \
-I/workspaces/cmake-general/tests/project/build/linux-clang-libstdc++-debug/src \
-g \
-fPIE \
-stdlib=libstdc++ \
-fcolor-diagnostics \
-fdebug-default-version=5 \
-Wall \
-Wextra \
-Wshadow \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Wcast-align \
-Wunused \
-Woverloaded-virtual \
-Wpedantic \
-Wconversion \
-Wsign-conversion \
-Wnull-dereference \
-Wdouble-promotion \
-Wformat=2 \
-Wsuggest-override \
-Wmisleading-indentation \
-Werror \
-fsanitize=address \
-fsanitize=undefined,bounds \
-fno-sanitize-recover=undefined,bounds \
-fno-omit-frame-pointer \
-std=c++20 \
-Winvalid-pch \
-fpch-instantiate-templates \
-Xclang \
-emit-pch \
-Xclang \
-include \
-Xclang \
/workspaces/cmake-general/tests/project/build/linux-clang-libstdc++-debug/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx \
-x \
c++-header \
-MD \
-MT \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch \
-MF \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch.d \
-o \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch \
-c \
/workspaces/cmake-general/tests/project/build/linux-clang-libstdc++-debug/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.cxx

```

but with `linux-clang-libc++-debug`

```nohighlight
/usr/local/bin/cmake \
-E \
__run_co_compile \
--launcher=/usr/bin/ccache \
--tidy="/usr/bin/clang-tidy;-header-filter=.;-extra-arg=-Wno-unknown-warning-option;-checks=-clang-diagnostic-unused-command-line-argument;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" \
--source=/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.cxx \
-- \
/usr/bin/clang++-13 \
-DCARES_STATICLIB \
-DFMT_SHARED \
-D_GLIBCXX_USE_CXX11_ABI=1 \
-I/workspaces/cmake-general/tests/project/src \
-I/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src \
-g \
-fPIE \
-stdlib=libc++ \
-fcolor-diagnostics \
-fdebug-default-version=5 \
-Wall \
-Wextra \
-Wshadow \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Wcast-align \
-Wunused \
-Woverloaded-virtual \
-Wpedantic \
-Wconversion \
-Wsign-conversion \
-Wnull-dereference \
-Wdouble-promotion \
-Wformat=2 \
-Wsuggest-override \
-Wmisleading-indentation \
-Werror \
-fsanitize=address \
-fsanitize=undefined,bounds \
-fno-sanitize-recover=undefined,bounds \
-fno-omit-frame-pointer \
-std=c++20 \
-Winvalid-pch \
-fpch-instantiate-templates \
-Xclang \
-emit-pch \
-Xclang \
-include \
-Xclang \
/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx \
-x \
c++-header \
-MD \
-MT \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch \
-MF \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch.d \
-o \
src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.pch \
-c \
/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.cxx

```

it does not find includes

```nohighlight
/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx:5:10:
error: 'iostream' file not found [clang-diagnostic-error]

```

**Both compiler invocations are nearly identica except for path and `-stdlib`**  
But also by changing the failing one to `libstdc++` it does not work, which is utterly strange?

I am out of luck, how can I debug further here?  
It seem its either a clang-tidy bug, or `__run_co_compile` does something weird? System includes should be handled by clang right?  
Also `compile_commands.json` is generated in the build dir.

Thanks for the help.

---

<div class="post-metadata">

### Author: ![gabyx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gabyx/32/2107_2.png) [@gabyx](https://discourse.cmake.org/u/gabyx)
#### Post date: [June 22, 2022, 5:33pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/2 "2022-06-22T17:33:10Z")

</div>

Also all input files are completely identical.

---

<div class="post-metadata">

### Author: ![gabyx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gabyx/32/2107_2.png) [@gabyx](https://discourse.cmake.org/u/gabyx)
#### Post date: [June 22, 2022, 5:35pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/3 "2022-06-22T17:35:55Z")

</div>

I guess cmake \_\_run\_co\_compile does some sideeffects depending on the location of `--source`  
which I do not understand

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [June 23, 2022, 9:52pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/4 "2022-06-23T21:52:23Z")

</div>

What if you run the command without cmake -E? Just run the command from the same directory that cmake is running it from with the same arguments. Sounds like a clang-tidy installation issue to me.

---

<div class="post-metadata">

### Author: ![gabyx](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gabyx/32/2107_2.png) [@gabyx](https://discourse.cmake.org/u/gabyx)
#### Post date: [June 24, 2022, 6:46am UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/5 "2022-06-24T06:46:17Z")

</div>

I think you mean without the above first part above ?

> [@gabyx](#):
>
> ```auto
> /usr/local/bin/cmake \
> -E \
> __run_co_compile \
> --launcher=/usr/bin/ccache \
> --tidy="/usr/bin/clang-tidy;-header-filter=.;-extra-arg=-Wno-unknown-warning-option;-checks=-clang-diagnostic-unused-command-line-argument;-warnings-as-errors=*;--extra-arg-before=--driver-mode=g++" \
> --source=/workspaces/cmake-general/tests/project/build/linux-clang-libc++/src/cli/CMakeFiles/cli.dir/cmake_pch.hxx.cxx \
> -- \
> 
> ```

Because without this **it works** (?).  
So I strangely guess its a \_\_run\_co\_compile problem? Do you know what it does? Does it inject include directories?

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [June 27, 2022, 11:35pm UTC](https://discourse.cmake.org/t/clang-tidy-does-not-find-include-iostream-with-run-co-compile/5910/6 "2022-06-27T23:35:17Z")

</div>

Could the error be coming from clang-tidy?
