diff mbox series

[ovs-dev,4/4] ofp-actions: Add compare to offsetof need for MSVC 2015/17

Message ID 20171101171907.14588-5-aserdean@ovn.org
State Accepted
Headers show
Series windows: Add support for compiling using 2015/2017 | expand

Commit Message

Alin-Gabriel Serdean Nov. 1, 2017, 5:19 p.m. UTC
Unfortunately starting from VS 2015, the "C" definition for `offsetof`
has been changed. Please see:
https://stackoverflow.com/questions/42725929/using-offsetof-with-enum-does-not-compile-in-visual-studio-2015/42726424

Several people reported the bug for 2015 and also 2017 (i.e. :
https://developercommunity.visualstudio.com/content/problem/22196/static-assert-cannot-compile-constexprs-method-tha.html
), but we don't have a fix yet.

This patch adds an explicit compare, although we could redefine the macro
for the same effect.

Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
---
 include/openvswitch/ofp-actions.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ben Pfaff Nov. 3, 2017, 6:40 p.m. UTC | #1
On Wed, Nov 01, 2017 at 07:19:07PM +0200, Alin Gabriel Serdean wrote:
> Unfortunately starting from VS 2015, the "C" definition for `offsetof`
> has been changed. Please see:
> https://stackoverflow.com/questions/42725929/using-offsetof-with-enum-does-not-compile-in-visual-studio-2015/42726424
> 
> Several people reported the bug for 2015 and also 2017 (i.e. :
> https://developercommunity.visualstudio.com/content/problem/22196/static-assert-cannot-compile-constexprs-method-tha.html
> ), but we don't have a fix yet.
> 
> This patch adds an explicit compare, although we could redefine the macro
> for the same effect.
> 
> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>

That's super weird.

If this solves the problem, it's fine with me.

Acked-by: Ben Pfaff <blp@ovn.org>
Anand Kumar Nov. 8, 2017, 1:16 a.m. UTC | #2
Acked-by: Anand Kumar <kumaranand@vmware.com>

Thanks,
Anand Kumar

On 11/1/17, 10:19 AM, "ovs-dev-bounces@openvswitch.org on behalf of Alin Gabriel Serdean" <ovs-dev-bounces@openvswitch.org on behalf of aserdean@ovn.org> wrote:

    Unfortunately starting from VS 2015, the "C" definition for `offsetof`
    has been changed. Please see:
    https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_42725929_using-2Doffsetof-2Dwith-2Denum-2Ddoes-2Dnot-2Dcompile-2Din-2Dvisual-2Dstudio-2D2015_42726424&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=imFxQ_aJ0_DP4dimFnQD-LfWi8kLVE68mKlRQs3sYLo&s=CpTwQKV4LcgBt--l8gTD87Dp-U7y_UrG_mMYWwSFWQY&e=
    
    Several people reported the bug for 2015 and also 2017 (i.e. :
    https://urldefense.proofpoint.com/v2/url?u=https-3A__developercommunity.visualstudio.com_content_problem_22196_static-2Dassert-2Dcannot-2Dcompile-2Dconstexprs-2Dmethod-2Dtha.html&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=imFxQ_aJ0_DP4dimFnQD-LfWi8kLVE68mKlRQs3sYLo&s=2acERJsAmdC4hO7OhvCR0DqqAA_TMnlOysxK3ZfCUgk&e=
    ), but we don't have a fix yet.
    
    This patch adds an explicit compare, although we could redefine the macro
    for the same effect.
    
    Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
    ---
     include/openvswitch/ofp-actions.h | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h
    index 03c1d11..25f61ef 100644
    --- a/include/openvswitch/ofp-actions.h
    +++ b/include/openvswitch/ofp-actions.h
    @@ -1128,7 +1128,7 @@ void *ofpact_finish(struct ofpbuf *, struct ofpact *);
         BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0);            \
                                                                             \
         enum { OFPACT_##ENUM##_SIZE                                         \
    -           = (offsetof(struct STRUCT, MEMBER)                           \
    +           = (offsetof(struct STRUCT, MEMBER) != 0                      \
                   ? offsetof(struct STRUCT, MEMBER)                         \
                   : OFPACT_ALIGN(sizeof(struct STRUCT))) };                 \
                                                                             \
    -- 
    2.10.2.windows.1
    
    _______________________________________________
    dev mailing list
    dev@openvswitch.org
    https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_mailman_listinfo_ovs-2Ddev&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=imFxQ_aJ0_DP4dimFnQD-LfWi8kLVE68mKlRQs3sYLo&s=nFUZCkxUXM5tAdr96klxAPotyDUoEhvcJoTQBwJtOXk&e=
diff mbox series

Patch

diff --git a/include/openvswitch/ofp-actions.h b/include/openvswitch/ofp-actions.h
index 03c1d11..25f61ef 100644
--- a/include/openvswitch/ofp-actions.h
+++ b/include/openvswitch/ofp-actions.h
@@ -1128,7 +1128,7 @@  void *ofpact_finish(struct ofpbuf *, struct ofpact *);
     BUILD_ASSERT_DECL(offsetof(struct STRUCT, ofpact) == 0);            \
                                                                         \
     enum { OFPACT_##ENUM##_SIZE                                         \
-           = (offsetof(struct STRUCT, MEMBER)                           \
+           = (offsetof(struct STRUCT, MEMBER) != 0                      \
               ? offsetof(struct STRUCT, MEMBER)                         \
               : OFPACT_ALIGN(sizeof(struct STRUCT))) };                 \
                                                                         \