Skip to content

cpp toolchain: stop passing -std=c++0x per default #18181

@davido

Description

@davido

Description of the bug:

After upgrading gcc version to 13 there are issues with different Bazel projects.

Consider this output:

  $ g++ -x c++ -std=c++0x -dM -E - </dev/null | grep __cplusplus
#define __cplusplus 201103L

However, without passing -std=c++0x option, the default is c++17:

  $ g++ -x c++ -dM -E - </dev/null | grep __cplusplus
#define __cplusplus 201703L

Now, trying to build abseil-cpp, this breakge is reported:

 ./absl/base/policy_checks.h:79:2: error: #error "C++ versions less than C++14 are not supported."
   79 | #error "C++ versions less than C++14 are not supported."
      |  ^~~~~

Where the Bazel command produced by Bazel@HEAD is:

  $ /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/k8-fastbuild/bin/absl/base/_objs/atomic_hook_test_helper/atomic_hook_test_helper.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/absl/base/_objs/atomic_hook_test_helper/atomic_hook_test_helper.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -Wall -Wextra -Wcast-qual -Wconversion-null -Wformat-security -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wundef -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -DNOMINMAX -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c absl/base/internal/atomic_hook_test_helper.cc -o bazel-out/k8-fastbuild/bin/absl/base/_objs/atomic_hook_test_helper/atomic_hook_test_helper.pic.o

Removing '-std=c++0x' makes this command work.

The code in ./absl/base/policy_checks.h:79:

// -----------------------------------------------------------------------------
// C++ Version Check
// -----------------------------------------------------------------------------

// Enforce C++14 as the minimum.
#if defined(_MSVC_LANG)
#if _MSVC_LANG < 201402L
#error "C++ versions less than C++14 are not supported."
#endif  // _MSVC_LANG < 201402L
#elif defined(__cplusplus)
#if __cplusplus < 201402L
#error "C++ versions less than C++14 are not supported."
#endif  // __cplusplus < 201402L
#endif

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Bump gcc version to 13 and build abseil-cpp@HEAD (https://github.com/abseil/abseil-cpp) with Bazel@HEAD.

My environment:

  $ gcc --version
cc (SUSE Linux) 13.0.1 20230412 (experimental) [revision d339e9802f758e051b0a1ef6db732ff846cbf4e3]
[...]

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

All released Bazel versions are affected including Bazel@HEAD.

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

There are a number of reports:

abseil/abseil-cpp#1431
protocolbuffers/protobuf#12393
https://stackoverflow.com/questions/75850778/error-c-versions-less-than-c14-are-not-supported-in-bazel-how-to-resolve

Any other information, logs, or outputs that you want to share?

There is a workaround, bump -std-option in .bazelrc:

build --cxxopt=-std=c++14
build --host_cxxopt=-std=c++14

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)team-Rules-CPPIssues for C++ rulestype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions