__maybe_unused for conditional struct field?

Hi,

I could be not making sense here since I am newbie to compiler and
not even sure if this is a problem that compiler should care to
address

I ran into this
https://github.com/cilium/cilium/pull/17370#discussion_r731170618

where the suggestion to add conditional field like below,

struct remote_endpoint_info {
        __u32 sec_label;
        __u32 tunnel_endpoint;
#ifdef ENABLE_VTEP
        mac_t vtep_mac;
#endif
        __u8 key;
};

but it cause misalignment issue with golang struct below:

// RemoteEndpointInfo implements the bpf.MapValue interface. It contains the
// security identity of a remote endpoint.
// +k8s:deepcopy-gen=true
   +k8s:deepcopy-gen:interfaces=github.com/cilium/cilium/pkg/bpf.MapValue
type RemoteEndpointInfo struct {
        SecurityIdentity uint32 `align:"sec_label"`
        TunnelEndpoint types.IPv4 `align:"tunnel_endpoint"`
        VtepMAC mac.Uint64MAC `align:"vtep_mac"`
        Key uint8 `align:"key"`
}

so out of my imagination without understanding things going on
underneath, I attempted to use __maybe_unused since I saw it being
used for stack variable,

struct remote_endpoint_info {
        __u32 sec_label;
        __u32 tunnel_endpoint;
       mac_t vtep_mac __maybe_unused;
        __u8 key;
};

the clang llvm did not complain error, but it has no effect on the
struct memory layout neither, so I wonder if __maybe_unused to struct
field is a thing, or if I am looking for wrong solution for the
problem, appreciate any input

Thanks

Vincent

I could be wrong, but I think __maybe_unused is an old way to spell [[maybe_unused]] which is documented here: https://eel.is/c++draft/dcl.attr.unused

In short it indicates that an entity might be intentionally unused, so it suppresses a warning that something might be accidentally unused. It should have no semantic effect (such as an impact on layout).