__maybe_unused for conditional struct field?


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

I ran into this

where the suggestion to add conditional field like below,

struct remote_endpoint_info {
        __u32 sec_label;
        __u32 tunnel_endpoint;
        mac_t vtep_mac;
        __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
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



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).