Skip to content

base: fix ABSL_ATTRIBUTE_WARN_UNUSED with gcc <= 12#2044

Open
jolivain wants to merge 1 commit into
abseil:masterfrom
jolivain:fix_warn_unused_with_gcc12
Open

base: fix ABSL_ATTRIBUTE_WARN_UNUSED with gcc <= 12#2044
jolivain wants to merge 1 commit into
abseil:masterfrom
jolivain:fix_warn_unused_with_gcc12

Conversation

@jolivain
Copy link
Copy Markdown

Gcc <= 12 does not support mixing standard C++ attributes with GNU attributes. See [1].

This can lead to build failures such as [2] [3] and [4]. In those situations, the compilation fails with error such as:

/usr/include/absl/base/attributes.h:1076:36: error: expected identifier before '[' token

Gcc maintainers mentioned in [1] comment 9 that this bugfix will not be backported in Gcc 12. Gcc 12 is still used in LTS distributions. For example, it is included in Debian 12 (Bookworm), which is still supported until 2028. See [5].

This commit adds a workaround for gcc <= 12 which uses attribute in that case, which fixes the compilation failure.

[1] https://gcc.gnu.org/PR69585
[2] protocolbuffers/protobuf#26383
[3] https://autobuild.buildroot.org/results/33f6cfd37cb48c15a53b3e7123d5ce8388a0f2ab/build-end.log
[4] https://gitlab.com/buildroot.org/buildroot/-/jobs/13904066346
[5] https://www.debian.org/releases/bookworm/

Gcc <= 12 does not support mixing standard C++ attributes with
GNU attributes. See [1].

This can lead to build failures such as [2] [3] and [4]. In those
situations, the compilation fails with error such as:

    /usr/include/absl/base/attributes.h:1076:36: error: expected identifier before '[' token

Gcc maintainers mentioned in [1] comment 9 that this bugfix will
not be backported in Gcc 12. Gcc 12 is still used in LTS
distributions. For example, it is included in Debian 12 (Bookworm),
which is still supported until 2028. See [5].

This commit adds a workaround for gcc <= 12 which uses
__attribute__ in that case, which fixes the compilation failure.

[1] https://gcc.gnu.org/PR69585
[2] protocolbuffers/protobuf#26383
[3] https://autobuild.buildroot.org/results/33f6cfd37cb48c15a53b3e7123d5ce8388a0f2ab/build-end.log
[4] https://gitlab.com/buildroot.org/buildroot/-/jobs/13904066346
[5] https://www.debian.org/releases/bookworm/

Signed-off-by: Julien Olivain <ju.o@free.fr>
@derekmauro
Copy link
Copy Markdown
Member

The proposed patch happens to solve this particular problem, but it is not a general solution.

Consider what would happen if we had flipped the definition syntax so that ABSL_ATTRIBUTE_WARN_UNUSED uses GNU syntax and PROTOBUF_EXPORT uses C++ attributes:

#define ABSL_ATTRIBUTE_WARN_UNUSED __attribute__((warn_unused))
#define PROTOBUF_EXPORT [[gnu::visibility("default")]]

We are left with the same problem, and by making this change, we might actually introduce the same problem in a new location.

It is almost as if we need an all-or-none approach to how we declare these attributes.

@jolivain
Copy link
Copy Markdown
Author

jolivain commented May 8, 2026

I see.

Since gcc-12 is phasing out and this issue seems a specific case on class declaration only, we could simply define an empty macro, as if the compile was not supporting it.

#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 13
#define ABSL_ATTRIBUTE_WARN_UNUSED
#else
#define ABSL_ATTRIBUTE_WARN_UNUSED [[gnu::warn_unused]]
#endif
#else
#define ABSL_ATTRIBUTE_WARN_UNUSED
#endif

What do you think?

arnout pushed a commit to buildroot/buildroot that referenced this pull request May 15, 2026
libabseil-cpp headers can break some packages build, like protobuf,
when compiled with gcc 12. See [1] [2]. The issue has been reported
in protobuf upstream, in [3].

The issue is due to gcc <= 12 not supporting the mix of standard
C++ attributes with GNU attributes. See [4].

Gcc 12 has been removed from Buildroot internal toolchains in
commit [5], but gcc 12 can still be present in external toolchains
or on the host. This is currently the case of the Buildroot Docker
reference image, based on Debian 12 (Bookworm).

This commit fixes the issue by adding a package patch.

Fixes:
- [1] [2] and many more.

[1] https://gitlab.com/buildroot.org/buildroot/-/jobs/13904066346
[2] https://autobuild.buildroot.org/results/33f6cfd37cb48c15a53b3e7123d5ce8388a0f2ab
[3] protocolbuffers/protobuf#26383
[4] https://gcc.gnu.org/PR69585
[5] https://gitlab.com/buildroot.org/buildroot/-/commit/58cf7c51da3ae4804332f68ee934e153d695d047
[6] abseil/abseil-cpp#2044

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Romain Naour <romain.naour@smile.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants