On Thu, May 02, 2024 at 02:48:26PM -0700, Stephen Hemminger wrote:
> There are already constant checks like this elsewhere in the file.

Yes, but they're in macros, rather than inlined functions, so my
understanding was that at compile time, macro expansion has put the
memorder constant in the _Static_assert call as opposed to still being
a function parameter in the inline definition.

This is also the same approach used by the generic implementation
(lib/eal/include/generic/rte_pause.h), the inline functions use assert
and the macros use RTE_BUILD_BUG_ON.

To give a minimal example, the following inline function doesn't
compile (Godbolt demo here https://godbolt.org/z/aPqTf3v4o ):

static inline __attribute__((always_inline)) void
add(int *dst, int val)
{
        _Static_assert(val != 0, "adding zero does nothing");
        *dst += val;
}

But as a macro it does ( https://godbolt.org/z/x4a8fTf8h ):

#define add(dst, val) do {                                    \
        _Static_assert(val != 0, "adding zero does nothing"); \
        *(dst) += (val);                                      \
} while(0);

I don't believe this is a compiler bug as both GCC and Clang produce the
same error message.

Reply via email to