Skip to content

protobuf 34.0: build fails with GCC ≤12 + shared libs due to mixed attribute syntax #26383

@haampie

Description

@haampie

protobuf 34.0 fails to build with GCC ≤12 when building shared libraries (-DBUILD_SHARED_LIBS=ON). GCC 13+ and static builds work fine.

10af44b added PROTOBUF_FUTURE_ADD_EARLY_WARN_UNUSED (→ ABSL_ATTRIBUTE_WARN_UNUSED[[gnu::warn_unused]]). In shared builds, PROTOBUF_EXPORT expands to __attribute__((visibility("default"))), producing declarations like:

class __attribute__((visibility("default"))) [[gnu::warn_unused]] CodedInputStream {

GCC ≤12 cannot parse mixed GNU and C++11 attributes in this position (GCC#69585, fixed in GCC 13).

The same class of bug was previously fixed for alignas in baeab50, and reported in #19447 (auto-closed) and #16867.

port_def.inc:158:47: error: expected identifier before '[' token
  158 | #define PROTOBUF_FUTURE_ADD_EARLY_WARN_UNUSED ABSL_ATTRIBUTE_WARN_UNUSED
      |                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~
coded_stream.h:151:23: note: in expansion of macro 'PROTOBUF_FUTURE_ADD_EARLY_WARN_UNUSED'
  151 | class PROTOBUF_EXPORT PROTOBUF_FUTURE_ADD_EARLY_WARN_UNUSED CodedInputStream {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Tested with GCC 11.5, 12.4 (both fail), and 13.3 (passes), all with abseil-cpp 20240722.0 and -std=c++17.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions