On 2025-12-16 03:53, Alejandro Colomar wrote:

See the following program, to understand all the placements.  I've used
attributes that don't make sense, to trigger diagnostics, which make it
more visible to what they apply.

        alx@devuan:~/tmp$ cat attr.c
        [[gnu::packed]] void f(void), g(void);  // Attributed:  f, g
        void [[gnu::packed]] h(void);  // Attributed:  void
        void i [[gnu::packed]](void);  // Attributed:  i
        void j(void) [[gnu::packed]];  // Attributed:  void(void)

        [[pure]] enum a {A} v, vv;  // Attributed:  v, vv
        enum [[pure]] b {B} w;  // Attributed:  enum b
        enum c [[pure]] {C} x;  // Syntax error
        enum d {D} [[pure]] y;  // I think this won't work.
        enum e {E} z [[pure]], zz;  // Attributed:  z

These examples unfortunately confused me more than they helped. They would be better if they used attributes that made sense for what's being declared. For example:

  enum d {D} [[pure]] y;

conforms to C23 and so "works" in some sense. However, GCC rightly issues two warnings for it because it is dubious for one reason (the [[pure]] applies to y's type, but not to enum d in general) and dubious for another (types can't be pure).

Also, there are exceptions to the guidelines that you gave. For example, "[[fallthrough]];" doesn't follow the guidelines.

Reply via email to