[cfe-dev] Overeager -Wswitch

Kim Gräsman via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 16 11:55:02 PDT 2015


Thanks, that sounds like a plausible explanation.

FWIW, I've filed a bug on libstdc++:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67996.

And had a pull request accepted to work around this in Poco using an
if/else chain instead of a switch:
https://github.com/pocoproject/poco/commit/883cdb7b14f6738e9b89578bc24806e1b905426b

I suspect libstdc++ won't change, but at least I've worked around my
immediate problem.

Thanks!

- Kim

On Fri, Oct 16, 2015 at 5:23 PM, James Y Knight <jyknight at google.com> wrote:
> If it was actually the last value, that wouldn't be an issue. But it's
> actually set to 1L << 16 which is not any of the real values. I expect
> they're using this as a trick to force the type of the enum to be a 32-bit
> int, since before C++11, there was no way to specify the type of the enum
> directly.
>
> If that's so, they could switch to using "enum _Ios_Fmtflags : uint32_t"
> now.
>
> On Fri, Oct 16, 2015 at 9:00 AM, Yury Gribov via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>>
>> On 10/11/2015 09:59 PM, Joerg Sonnenberger via cfe-dev wrote:
>>>
>>> On Sun, Oct 11, 2015 at 07:58:32PM +0200, Kim Gräsman wrote:
>>>>
>>>> Hi Joerg,
>>>>
>>>> On Sat, Oct 10, 2015 at 1:33 PM, Joerg Sonnenberger via cfe-dev
>>>> <cfe-dev at lists.llvm.org> wrote:
>>>>>
>>>>> On Sat, Oct 10, 2015 at 10:21:17AM +0200, Kim Gräsman via cfe-dev
>>>>> wrote:
>>>>>>
>>>>>> 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?
>>>>>
>>>>>
>>>>> add GCC diagnostic push
>>>>> #pragma GCC diagnostic ignored "-Wswitch"
>>>>> ... your function here...
>>>>> #pragma GCC diagnostic pop
>>>>>
>>>>> I think it also works with clang as pragma group.
>>>>
>>>>
>>>> Thanks, that's what I was looking for in the way of disabling. To
>>>> confirm, #pragma clang diagnostic also works.
>>>>
>>>> I think we've agreed to rewrite the function in Poco using if/else
>>>> instead of switch, because it was hard to find a switch phrasing that
>>>> worked with all -W combinations (-Weverything overrode the #pragma
>>>> diagnostic and threw diagnostics for code that worked with -Wall).
>>>>
>>>> That said, it might be worth trying to make Clang aware of libstdc++'s
>>>> enum convention, but I haven't thought of a way to do so yet.
>>>
>>>
>>> I don't think there is anything Clang can or should do here, but please
>>> fill an upstream report against GCC if they still do it in the most
>>> recent version.
>>
>>
>> Using the last enum value (often suffixed with "_end" or "_last") to track
>> total number of values is a common coding practice so I'm not sure they are
>> going to fix this.
>>
>> -Y
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>



More information about the cfe-dev mailing list