diff mbox

[ovs-dev] gcc: Fix compile errors due to anonymous union initilization.

Message ID 1455760822-117996-2-git-send-email-u9012063@gmail.com
State Accepted
Headers show

Commit Message

William Tu Feb. 18, 2016, 2 a.m. UTC
gcc 4.4.7 lets you initialize named fields, and assign to anonymous union members,
but cannot statically initialize a named member of an anonymous union. This causes
errors when doing make:
fproto/fail-open.c: In function ‘send_bogus_packet_ins’:
ofproto/fail-open.c:130: error: unknown field ‘pin’ specified in initializer
ofproto/fail-open.c:131: error: unknown field ‘up’ specified in initializer
ofproto/fail-open.c:132: error: unknown field ‘packet’ specified in initializer
ofproto/fail-open.c:132: warning: missing braces around initializer
ofproto/fail-open.c:132: warning: (near initialization for ‘am.<anonymous>.pin.up’)
ofproto/fail-open.c:134: error: extra brace group at end of initializer

Examaple: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42875
We can either assign a name to the union or, in this patch, remove the unnecessary union.

Signed-off-by: William Tu <u9012063@gmail.com>
---
 ofproto/connmgr.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Ben Pfaff Feb. 22, 2016, 6:06 p.m. UTC | #1
On Wed, Feb 17, 2016 at 06:00:22PM -0800, William Tu wrote:
> gcc 4.4.7 lets you initialize named fields, and assign to anonymous union members,
> but cannot statically initialize a named member of an anonymous union. This causes
> errors when doing make:
> fproto/fail-open.c: In function ‘send_bogus_packet_ins’:
> ofproto/fail-open.c:130: error: unknown field ‘pin’ specified in initializer
> ofproto/fail-open.c:131: error: unknown field ‘up’ specified in initializer
> ofproto/fail-open.c:132: error: unknown field ‘packet’ specified in initializer
> ofproto/fail-open.c:132: warning: missing braces around initializer
> ofproto/fail-open.c:132: warning: (near initialization for ‘am.<anonymous>.pin.up’)
> ofproto/fail-open.c:134: error: extra brace group at end of initializer
> 
> Examaple: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42875
> We can either assign a name to the union or, in this patch, remove the unnecessary union.
> 
> Signed-off-by: William Tu <u9012063@gmail.com>

Well, that's going to bite us again.

Thanks for the patch.  Applied!
diff mbox

Patch

diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h
index fb7573e..b737427 100644
--- a/ofproto/connmgr.h
+++ b/ofproto/connmgr.h
@@ -60,13 +60,11 @@  struct ofproto_async_msg {
     uint16_t controller_id;     /* Controller ID to send to. */
 
     enum ofputil_async_msg_type oam;
-    union {
-        /* OAM_PACKET_IN. */
-        struct {
-            struct ofputil_packet_in up;
-            int max_len;                /* From action, or -1 if none. */
-        } pin;
-    };
+    /* OAM_PACKET_IN. */
+    struct {
+        struct ofputil_packet_in up;
+        int max_len;                /* From action, or -1 if none. */
+    } pin;
 };
 void ofproto_async_msg_free(struct ofproto_async_msg *);