Yesterday I did: > 2024-07-29 Bruno Haible <br...@clisp.org> > > Avoid g++ "warning: attributes are not permitted in this position". > * m4/gnulib-common.m4 (gl_COMMON_BODY): Add more comments. Define > _GL_BRACKET_USABLE. ...
But I'm not happy with it, as it disables the use of the [[...]] attributes entirely. A better way of handling this matter is - by distinguishing function declarations from other declarations, - by omitting the 'extern' keyword from specific function declarations (since 'extern' is optional, per ISO C 23 § 6.2.2.(5)). Here are two patches: - 0001 reverts that part of yesterday's change and places the attributes in a position where both C and C++ accept them. - 0002 documents the placements of attribute markers better. 2024-07-30 Bruno Haible <br...@clisp.org> attribute: Improve documentation. * lib/attribute.h: Clarify where to place the various attributes. 2024-07-30 Bruno Haible <br...@clisp.org> Reenable use of attributes in bracket syntax [[...]] (regr. yesterday). * m4/gnulib-common.m4 (gl_COMMON_BODY): Add more comments. Don't define _GL_BRACKET_USABLE. * lib/c++defs.h (_GL_EXTERN_C_FUNC): New macro. (_GL_FUNCDECL_RPL, _GL_FUNCDECL_RPL_1, _GL_FUNCDECL_SYS): Expect the attributes in an optional 4th argument. Expand them before the return type. * lib/arpa_inet.in.h: Update all _GL_FUNCDECL_RPL and _GL_FUNCDECL_SYS invocations. * lib/dirent.in.h: Likewise. * lib/error.in.h: Likewise. * lib/fcntl.in.h: Likewise. * lib/fnmatch.in.h: Likewise. * lib/glob.in.h: Likewise. * lib/iconv.in.h: Likewise. * lib/inttypes.in.h: Likewise. * lib/locale.in.h: Likewise. * lib/malloc.in.h: Likewise. * lib/math.in.h: Likewise. * lib/monetary.in.h: Likewise. * lib/netdb.in.h: Likewise. * lib/pthread.in.h: Likewise. * lib/search.in.h: Likewise. * lib/signal.in.h: Likewise. * lib/spawn.in.h: Likewise. * lib/stdio.in.h: Likewise. * lib/stdlib.in.h: Likewise. * lib/string.in.h: Likewise. * lib/sys_random.in.h: Likewise. * lib/sys_resource.in.h: Likewise. * lib/sys_socket.in.h: Likewise. * lib/sys_stat.in.h: Likewise. * lib/sys_time.in.h: Likewise. * lib/threads.in.h: Likewise. * lib/time.in.h: Likewise. * lib/uchar.in.h: Likewise. * lib/unistd.in.h: Likewise. * lib/utime.in.h: Likewise. * lib/wchar.in.h: Likewise. * lib/wctype.in.h: Likewise. * lib/c-vasprintf.h (c_aszprintf, c_vaszprintf, c_asprintf, c_vasprintf): Move _GL_ATTRIBUTE_NODISCARD back to the beginning of the declaration.
0001-Reenable-use-of-attributes-in-bracket-syntax-.-regr..patch.gz
Description: application/gzip
From a05ec21958eb6afb6c7e419b8fb543e26c0d00e1 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 30 Jul 2024 22:01:27 +0200 Subject: [PATCH 2/2] attribute: Improve documentation. * lib/attribute.h: Clarify where to place the various attributes. --- ChangeLog | 5 +++++ lib/attribute.h | 49 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6bf78d04ff..872cc0f6cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-07-30 Bruno Haible <br...@clisp.org> + + attribute: Improve documentation. + * lib/attribute.h: Clarify where to place the various attributes. + 2024-07-30 Bruno Haible <br...@clisp.org> Reenable use of attributes in bracket syntax [[...]] (regr. yesterday). diff --git a/lib/attribute.h b/lib/attribute.h index 604965a6d1..186faa5526 100644 --- a/lib/attribute.h +++ b/lib/attribute.h @@ -20,12 +20,49 @@ /* Provide public ATTRIBUTE_* names for the private _GL_ATTRIBUTE_* macros used within Gnulib. */ -/* These attributes can be placed in two ways: - - At the start of a declaration (i.e. even before storage-class - specifiers!); then they apply to all entities that are declared - by the declaration. - - Immediately after the name of an entity being declared by the - declaration; then they apply to that entity only. */ +/* The placement of these attributes depends on the kind of declaration + and, in some cases, also on the programming language (C vs. C++). + + In function declarations and function definitions: + + * ATTRIBUTE_NOTHROW must come after the parameter list. + + * The macros + ATTRIBUTE_CONST + ATTRIBUTE_PURE + DEPRECATED + MAYBE_UNUSED + NODISCARD + REPRODUCIBLE + UNSEQUENCED + must come before the return type, and more precisely: + - In a function declaration/definition without a storage-class + specifier: at the beginning of the declaration/definition. + - In a function declaration/definition with a storage-class + specifier: + - In C: before the storage-class specifier. + - In C++: between the storage-class specifier and the return type. + + * The other macros can be placed + - Either + - In a function declaration/definition without a storage-class + specifier: at the beginning of the declaration/definition. + - In a function declaration/definition with a storage-class + specifier: between the storage-class specifier and the return + type. + - Or after the parameter list, + ∙ but after ATTRIBUTE_NOTHROW if present. + + In other declarations, such as variable declarations: + + * Either + - In C: before the storage-class specifier. + - In C++: between the storage-class specifier and the return type. + Then they apply to all entities that are declared by the declaration. + + * Or immediately after the name of an entity being declared by the + declaration. Then they apply to that entity only. + */ #ifndef _GL_ATTRIBUTE_H #define _GL_ATTRIBUTE_H -- 2.34.1