0

I'm using JetBrains' CLion IDE. I would like to apply the include-what-you-use utility to some C++ code - but not just manually on the command line; rather, I want to go through CLion, and have the results reflected by the IDE somehow. Is that possible? I tried looking for an iwyu plugin for CLion, but no luck.

2
  • Might be of interest: youtrack.jetbrains.com/issue/CPP-3240/… Commented Apr 9 at 16:58
  • If there's no plugin, your best bet is writing one. How about clang-tidy? It has integration and misc-include-cleaner check seems to do roughly the same. EDIT: I just noticed you asked about clang-tidy first and got recommended iwyu :P Commented Apr 9 at 21:28

1 Answer 1

1

This feature has been around in CLion for some time (see https://www.jetbrains.com/help/clion/unused-include-directive.html). However, it was apparently not enabled by default in some releases, and may still not be. I believe support for IWYU pragmas was only added in a 2024 CLion release.

Go to Settings > Editor > Inspections > C/C++ > Potential Code Quality Issues and check the Possibly unused #include directive box. Also make sure that you are using CLion Nova (ReSharper C++ language engine) in Settings > Advanced Settings > CLion.

I'm using CLion 2025.1.3 on macOS 15.5 (Sequoia) and it's working beautifully for me.

Sign up to request clarification or add additional context in comments.

2 Comments

Accepting, although I'm only half-certain that the functionality is indeed exactly the same.
I agree that the CLion/Jetbrains docs aren't very revealing, but it works for me. Headers that don't seem to be needed are flagged by the IDE, and adding pragmas like // IWYU pragma: keep suppresses this flagging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.