IDE inspection seems to ignore or miss headers
TL;DR: This is about CLion not finding symbol usages in non-project headers. My comments below contain notes on the things I learned about this issue and a workaround I found. Can I avoid that workaround?
Hi,
I'm just getting started with CLion and Boost.Test and there are some warnings I see in the IDE that do not appear to be warranted. CMake builds the project without any issues and everything runs fine, it is just the IDE that sees issues.
One warning is "Macro 'BOOST_TEST_MODULE' is never used". The others are clang-tidy warnings on the BOOST_AUTO_TEST_CASE macro.
The project consists of two files:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(boostWarnings)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
include_directories(${Boost_INCLUDE_DIR})
add_executable(boostWarnings main.cpp)
main.cpp:
#define BOOST_TEST_MODULE Boost uses this macro
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(greenTest) {
BOOST_TEST(true);
}
What can I do in order to get rid of these warnings? I guess I need to make the IDE inspect the boost.test headers but I don't know how.
Thanks
Leo
Please sign in to leave a comment.
Update: boost-less, minified example.
I have four files now. "external.hpp" is outside the project (one directory up from the project directory). "internal.hpp", "main.cpp", and "CMakeLists.txt" are in the project. external.hpp and internal.hpp essentially do the same thing. When using internal.hpp there is no warning, when using external.hpp then there is a warning.
CMakeLists.txt:
main.cpp:
internal.hpp:
external.hpp:
Update 2: This also works with a global variable instead of a preprocessor macro.
I find it interesting that in all examples things declared in the project-external header (be it macros or other identifiers) are no problem for the inspections.
main.cpp:
internal.h:
external.h:
More notes on this:
I created a symlink to the external header location via 'ln -s .. additional-includes' and marked that as "Project Sources and Headers" in the project view. After updating the #include directive for external.h I still got the warning.
Funnily, the warning went away when I created an actual new directory in the project ("more-includes") and moved external.h there. Didn't even need to mark the directory in any way.
Why does this workaround work with a real directory but not with a symlink?!
Side note: Playing around with include_directories() in CMakeLists.txt does not seem to change anything, here.
Edit: The warning also goes away when the additional-includes symlink does not point to a parent of the project directory. I moved the external.h to an unrelated directory and let additional-includes point there and that did the trick.
Open question: How can I do this without symlinking stuff into my project directory?
Hello!
Before CLion 2018.2, if header files were not added explicitly to CMake, CLion wasn't able to understand that they belonged to the project and therefore wasn't able to provide any code insight features for such files.
Now, if you include the header or source file into any project file, CLion will automatically treat it as a project file as well, which means full code insight will work in there! That's why everything works fine for internal.h. But this works only if the file is located under the project root, so it won’t affect standard or 3rd party libraries located outside of the project. That's why it doesn't work for external.h.
More info: https://intellij-support.jetbrains.com/hc/en-us/articles/207253145-Project-can-be-compiled-correctly-but-highlighting-completion-refactorings-etc-in-CLion-are-not-working-CLion-fails-to-find-some-of-my-classes-What-to-do-, https://blog.jetbrains.com/clion/2018/06/clion-2018-2-eap-automatically-treats-included-files-as-project-files/.
Hi,
thanks for the clarification and background. I‘ll make up my mind then whether to stick with symlinks or ignore the warning for the boost.test use case.
Kind regards
Leo