https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127044

--- Comment #2 from Evgeny Grin <k2k at drgrin dot dev> ---
Yes, I'm using these simple workarounds in my code, but I believe that they are
workarounds for GCC bugs.

> The warning is correct, you shouldn't be using assume attribute in C89 this 
> way

The documentation states the opposite, in three places.

1. The construct is defined as a null *statement*.

"Attribute Syntax", subheading "Statement Attributes":

  In GNU C, an attribute specifier list may appear as part of a null
  statement.  The attribute goes before the semicolon.

"Statement Attributes", section intro:

  GCC allows attributes to be set on null statements.

2. The "assume" entry claims exactly this usage is portable to C89.

"Statement Attributes", assume:

  The assume attribute with a null statement serves as portable
  assumption. [...] This is a GNU variant of the ISO C++23 standard
  assume attribute, but it can be used in any version of both C and C++.

3. The warning is documented as being about declarations.

-Wdeclaration-after-statement:

  Warn when a declaration is found after a statement in a block.

A null statement is not a declaration, so by the documentation this
warning does not apply to it.  Nothing in either section restricts the
attribute to the beginning of a block; the position within the block is
not mentioned at all.

Also: the fallthrough attribute is documented the same way.

"Statement Attributes", fallthrough:

  The fallthrough attribute with a null statement serves as a fallthrough
  statement.

It is described by the same formulation, in the same table, and it can be
used after a statement in C89 with no diagnostic.  The two attributes are
documented identically, yet only assume is treated as a declaration.

Reply via email to