2
votes

I'm running iwyu over my code base, and there are a few files where it insists I add

#include <cxxabi.h>  // for __forced_unwind

I was able to ablate code and find that it seems related to cv.wait(mu).

Specifically, the no predicate version.

If I remove cv.wait(mu), iwyu no longer suggests cxxabi.h.

What is this __forced_unwind function, why is iwyu recommending it, and can this safely be ignored?

Minimal test case:

// foo.cpp

#include <condition_variable>
#include <mutex>

void foo(std::condition_variable_any* cv, std::mutex* mu) {
  cv->wait(*mu);
}
src/foo.cpp should add these lines:
#include <cxxabi.h>            // for __forced_unwind

src/foo.cpp should remove these lines:

The full include-list for src/foo.cpp:
#include <cxxabi.h>            // for __forced_unwind
#include <condition_variable>  // for condition_variable_any
#include <mutex>               // for mutex
---
Seems like the standard header in libstdc++ has this covered by including <cxxabi_forced.h>: github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/std/… So my guess us that iwyu is just not aware of that? - user4442671
@Frank Thanks for pointing that out. I added { include: [ "<bits/cxxabi_forced.h>", private, "<condition_variable>", public ] }, to the imp file and that took care of it for now. Not sure whether I want to include <condition_variable> whenever some c++ header uses __forced_unwind, but I'll cross that bridge later. If you make a top-level answer, I'll accept it. - user100046
In my case it was <ctime> which caused this, so I added { include: [ "<bits/cxxabi_forced.h>", private, "<ctime>", public ] }, - Flow