xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* Invalid _Static_assert expanded from HASH_CALLBACKS_CHECK
@ 2021-05-24  4:29 Roberto Bagnara
  2021-05-25  8:58 ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Roberto Bagnara @ 2021-05-24  4:29 UTC (permalink / raw)
  To: xen-devel


Hi there.

I stumbled upon parsing errors due to invalid uses of
_Static_assert expanded from HASH_CALLBACKS_CHECK where
the tested expression is not constant, as mandated by
the C standard.

Judging from the following comment, there is partial awareness
of the fact this is an issue:

#ifndef __clang__ /* At least some versions dislike some of the uses. */
#define HASH_CALLBACKS_CHECK(mask) \
     BUILD_BUG_ON((mask) > (1U << ARRAY_SIZE(callbacks)) - 1)

Indeed, this is not a fault of Clang: the point is that some
of the expansions of this macro are not C.  Moreover,
the fact that GCC sometimes accepts them is not
something we can rely upon:

$ cat p.c
void f() {
static const int x = 3;
_Static_assert(x < 4, "");
}
$ gcc -c -O p.c
$ gcc -c p.c
p.c: In function ‘f’:
p.c:3:20: error: expression in static assertion is not constant
3 | _Static_assert(x < 4, "");
| ~^~
$

Finally, I think this can be easily avoided: instead
of initializing a static const with a constant expression
and then static-asserting the static const, just static-assert
the constant initializer.

Kind regards,

    Roberto Bagnara


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-06-07 16:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24  4:29 Invalid _Static_assert expanded from HASH_CALLBACKS_CHECK Roberto Bagnara
2021-05-25  8:58 ` Jan Beulich
2021-05-28  9:59   ` Roberto Bagnara
2021-05-28 10:07     ` Jan Beulich
2021-05-28 15:44   ` Tim Deegan
2021-05-31  6:45     ` Jan Beulich
2021-06-07 16:20       ` Tim Deegan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).