[ovs-dev] [PATCH] lib/unaligned.h - Fix C++ compiler issue with BUILD_ASSERT on Windows

Sairam Venugopal vsairam at vmware.com
Wed Dec 20 00:45:04 UTC 2017


Hi Ben,

I did consider updating the definition of BUILD_ASSERT, however, that would involve changing all existing definitions (even non-expression context).
This issue is prevalent on both Linux and Windows when we start compiling in C++ 11.

Associated post:
https://stackoverflow.com/questions/31311748/is-there-any-way-to-slip-a-static-assert-into-an-expression-in-iso-c11

The ideal fix would be to not use static_assert as an expression in C++11 mode. 
Currently, we hit this issue here : https://github.com/openvswitch/ovs/blob/master/lib/unaligned.h#L172

You can disregard this patch for the time being since we will need to fix this on both Linux and Windows.

Thanks,
Sairam



On 12/19/17, 3:45 PM, "Ben Pfaff" <blp at ovn.org> wrote:

>On Tue, Dec 19, 2017 at 03:32:27PM -0800, Sairam Venugopal wrote:
>> A static assert declaration may appear at block scope (as a block
>> declaration) and inside a class body (as a member declaration). However,
>> unlike sizeof, static_assert cannot be used as an expression and this is
>> strictly enforced on MSVC. error C2059: syntax error : static_assert
>> 
>> Signed-off-by: Sairam Venugopal <vsairam at vmware.com>
>
>I'd really prefer to adjust the definition of BUILD_ASSERT so that it
>can be used in any expression context.  Did you consider that?


More information about the dev mailing list