'default-const-init-field-unsafe' warning complains about allocating
structures on stack if they have any const fields.  We use this for
classifier rules that are embedded into many other structures:

  ofproto/ofproto.c:4980:26:
    error: default initialization of an object of type
    'struct rule_criteria' with const member leaves the
    object uninitialized [-Werror,-Wdefault-const-init-field-unsafe]
   4980 |     struct rule_criteria criteria;
        |                          ^
  ./lib/classifier.h:356:15:
    note: member 'priority' declared 'const' here
    356 |     const int priority;
        |               ^

Priority is marked as const as it is not supposed to be changed after
the rule creation, as that would break the classifier logic.  Any code
that changes the value is clearly seen, as it requires the explicit
CONST_CAST.  Initialization functions are the only places where this is
happening.  And these functions are always called for all the instances
allocated on stack, but clang fails to recognize this.

I believe, described code pattern is useful, so it's better to turn
off the warning instead of making the field non-const.  Alternative
would be to use an explicit initializer for every stack allocation
to silence the warning, but it feels like a bit too much.

Signed-off-by: Ilya Maximets <[email protected]>
---
 configure.ac | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure.ac b/configure.ac
index 3cf6557df..7a8b22a7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -182,6 +182,7 @@ OVS_ENABLE_OPTION([-Wmultistatement-macros])
 OVS_ENABLE_OPTION([-Wcast-align=strict])
 OVS_ENABLE_OPTION([-Wno-null-pointer-arithmetic])
 OVS_ENABLE_OPTION([-Warray-bounds-pointer-arithmetic])
+OVS_ENABLE_OPTION([-Wno-default-const-init-field-unsafe])
 OVS_CONDITIONAL_CC_OPTION([-Wno-unused], [HAVE_WNO_UNUSED])
 OVS_CONDITIONAL_CC_OPTION([-Wno-unused-parameter], [HAVE_WNO_UNUSED_PARAMETER])
 OVS_ENABLE_WERROR_TOP
-- 
2.51.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to