[cfe-dev] Overeager -Wswitch

Kim Gräsman via cfe-dev cfe-dev at lists.llvm.org
Sat Oct 10 01:21:17 PDT 2015


Hi all,

We have a codebase using the Poco library and libstdc++. We'd like to
use -Wswitch for our own code, but as soon as we include one of Poco's
headers we get a -Wswitch warning:

In file included from .../Poco/BinaryReader.h:25:
.../Poco/MemoryStream.h:87:12: warning: enumeration value
'_S_ios_seekdir_end' not handled in switch [-Wswitch]
                        switch (way)
                                ^
(source: https://github.com/pocoproject/poco/blob/develop/Foundation/include/Poco/MemoryStream.h#L87)

This turns out not to be a problem in Poco, but a quirk in libstdc++;
they define a last-enumerator, _S_ios_seekdir_end, see here:
https://github.com/gcc-mirror/gcc/blob/7c62dfbbcd3699efcbbadc9fb3aa14f23a123add/libstdc%2B%2B-v3/include/bits/ios_base.h#L187

This construct looks a little unconventional, but I don't know enough
about the library spec to say whether it's conforming.

So Poco has a fully covered switch per the abstract standard, but on
top of libstdc++ Clang rightfully discovers it doesn't. And because of
Poco's inline impl, we're stuck in the middle...

Is there a way to trim -Wswitch to discover this scenario? I could
work on a patch if it seems doable, but I'm not sure how to address it
without short-circuiting -Wswitch for all system headers, for example.

Alternatively, if we could get a patch into Poco, is there something
like MSVC's #pragma(warning:disable) for Clang, so they could
selectively silence the warning around this function?

Thanks for any ideas,
- Kim



More information about the cfe-dev mailing list