Skip to content

Commit fe53593

Browse files
tonyliaosscopybara-github
authored andcommitted
Bump minimum C++ version to C++17 after branch cut for v29.
Branch cut for v29 is done on 2024-09-30: https://github.com/protocolbuffers/protobuf/releases/tag/v29.0-rc1 The next version v30 will be a breaking release. The release date is scheduled after the EOL of C++14 support on 2024-12-15 for Google open source projects generally: https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md This commit allows us to start taking advantage of C++17 features now. Some issues I ran into while upgrading: Two GCC 9.5 bugs related to -Wunused-but-set-parameter: - https://godbolt.org/z/qo51cKe7b - https://godbolt.org/z/65qW3vGhP Another GCC warning related to -Wself-assign in a template. There is a custom ASAN check that is not yet open sourced. I'll see if I can open source them in a subsequent commit. #test-continuous PiperOrigin-RevId: 687435042
1 parent b93b8e5 commit fe53593

File tree

10 files changed

+54
-38
lines changed

10 files changed

+54
-38
lines changed

.github/workflows/test_cpp.yml

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
-c "set -ex;
131131
sccache -z;
132132
cmake . -DWITH_PROTOC=/workspace/${{ steps.cross-compile.outputs.protoc }}
133-
-Dprotobuf_BUILD_LIBUPB=OFF -Dprotobuf_BUILD_CONFORMANCE=ON -DCMAKE_CXX_STANDARD=14
133+
-Dprotobuf_BUILD_LIBUPB=OFF -Dprotobuf_BUILD_CONFORMANCE=ON -DCMAKE_CXX_STANDARD=17
134134
-Dprotobuf_WITH_ZLIB=OFF ${{ env.SCCACHE_CMAKE_FLAGS }};
135135
cmake --build . --parallel 20;
136136
ctest --parallel 20;
@@ -141,15 +141,13 @@ jobs:
141141
fail-fast: false # Don't cancel all jobs if one fails.
142142
matrix:
143143
include:
144-
- flags: -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=14 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
144+
- flags: -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
145145
- name: Ninja
146-
flags: -G Ninja -DCMAKE_CXX_STANDARD=14 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
146+
flags: -G Ninja -DCMAKE_CXX_STANDARD=17 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
147147
continuous-only: true
148148
- name: Shared
149-
flags: -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=14 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
149+
flags: -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=17 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
150150
continuous-only: true
151-
- name: C++17
152-
flags: -DCMAKE_CXX_STANDARD=17 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
153151
- name: C++20
154152
flags: -DCMAKE_CXX_STANDARD=20 -Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
155153
- name: Fetch
@@ -217,15 +215,15 @@ jobs:
217215
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-f39fc8b4e244fe5cd4c7138d0b6959a52b46ca48
218216
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
219217
command: >-
220-
/install.sh -DCMAKE_CXX_STANDARD=14 ${{ env.SCCACHE_CMAKE_FLAGS }}
218+
/install.sh -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }}
221219
${{ matrix.flags }}
222220
-Dprotobuf_BUILD_SHARED_LIBS=ON \&\&
223221
/test.sh
224222
${{ env.SCCACHE_CMAKE_FLAGS }}
225223
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON
226224
-Dprotobuf_BUILD_PROTOBUF_BINARIES=OFF
227225
-Dprotobuf_BUILD_CONFORMANCE=ON
228-
-DCMAKE_CXX_STANDARD=14
226+
-DCMAKE_CXX_STANDARD=17
229227
${{ matrix.flags }}
230228
231229
# This test should always be skipped on presubmit
@@ -253,21 +251,19 @@ jobs:
253251
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/cmake:3.16.9-f39fc8b4e244fe5cd4c7138d0b6959a52b46ca48
254252
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
255253
command: >-
256-
/install.sh -DCMAKE_CXX_STANDARD=14 ${{ env.SCCACHE_CMAKE_FLAGS }}
254+
/install.sh -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }}
257255
-Dprotobuf_USE_EXTERNAL_GTEST=ON -Dprotobuf_FETCH_DEPENDENCIES=OFF
258256
-Dprotobuf_BUILD_EXAMPLES=OFF \&\&
259257
mkdir examples/build \&\&
260258
cd examples/build \&\&
261-
cmake .. -DCMAKE_CXX_STANDARD=14 \&\&
259+
cmake .. -DCMAKE_CXX_STANDARD=17 \&\&
262260
cmake --build .
263261
264262
linux-cmake-gcc:
265263
strategy:
266264
fail-fast: false # Don't cancel all jobs if one fails.
267265
matrix:
268266
include:
269-
- name: C++14
270-
flags: -DCMAKE_CXX_STANDARD=14
271267
- name: C++17
272268
flags: -DCMAKE_CXX_STANDARD=17
273269
continuous-only: true
@@ -331,7 +327,7 @@ jobs:
331327
/bin/bash -cex '
332328
cd /workspace;
333329
sccache -z;
334-
cmake . -DCMAKE_CXX_STANDARD=14 ${{ env.SCCACHE_CMAKE_FLAGS }};
330+
cmake . -DCMAKE_CXX_STANDARD=17 ${{ env.SCCACHE_CMAKE_FLAGS }};
335331
cmake --build . --parallel 20;
336332
ctest --verbose --parallel 20;
337333
sccache -s'
@@ -391,7 +387,6 @@ jobs:
391387
include:
392388
- name: MacOS CMake
393389
os: macos-13
394-
flags: -DCMAKE_CXX_STANDARD=14
395390
cache-prefix: macos-cmake
396391
continuous-only: true
397392
- name: Windows CMake
@@ -430,7 +425,9 @@ jobs:
430425
cache-prefix: windows-2022-cmake
431426
- name: Windows CMake Install
432427
os: windows-2022
433-
install-flags: -G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_TESTS=OFF
428+
install-flags: >-
429+
-G Ninja -Dprotobuf_WITH_ZLIB=OFF
430+
-Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_TESTS=OFF
434431
flags: >-
435432
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
436433
-Dprotobuf_REMOVE_INSTALLED_HEADERS=ON
@@ -478,7 +475,9 @@ jobs:
478475
uses: protocolbuffers/protobuf-ci/bash@v3
479476
with:
480477
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
481-
command: cmake . ${{ matrix.install-flags }} ${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
478+
command: >-
479+
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.install-flags }}
480+
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
482481
- name: Build for install
483482
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
484483
shell: bash
@@ -501,7 +500,9 @@ jobs:
501500
uses: protocolbuffers/protobuf-ci/bash@v3
502501
with:
503502
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
504-
command: cmake . ${{ matrix.flags }} ${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
503+
command: >-
504+
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.flags }}
505+
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
505506
506507
- name: Build
507508
if: ${{ !matrix.continuous-only || inputs.continuous-run }}

ci/Linux.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import common.bazelrc
22

3-
build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
3+
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
44
build --cxxopt="-Woverloaded-virtual"
55
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations"
6+

ci/Windows.bazelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import common.bazelrc
22

33
# Workaround for maximum path length issues
4+
build --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
45
startup --output_user_root=C:/tmp --windows_enable_symlinks
5-
common --enable_runfiles
6+
common --enable_runfiles
7+

ci/macOS.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import common.bazelrc
22

3-
build --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
3+
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
44
build --cxxopt="-Woverloaded-virtual"
55
build --copt="-Werror" --copt="-Wno-sign-compare" --copt="-Wno-sign-conversion" --copt="-Wno-error=sign-conversion" --copt="-Wno-deprecated-declarations"
66
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
77
common --xcode_version_config=@com_google_protobuf//.github:host_xcodes
8+

examples/.bazelrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
common --enable_platform_specific_config
22

3-
build:linux --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
4-
build:macos --cxxopt=-std=c++14 --host_cxxopt=-std=c++14
3+
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
4+
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
55

6-
common:windows --enable_runfiles
6+
common:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 --enable_runfiles
77

88
build --experimental_remote_cache_eviction_retries=5
99
build --remote_download_outputs=all

src/google/protobuf/arena_unittest.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,11 +1541,7 @@ TEST(ArenaTest, ClearOneofMessageOnArena) {
15411541

15421542
#ifndef PROTOBUF_ASAN
15431543
EXPECT_NE(child->moo_int(), 100);
1544-
#else
1545-
#if GTEST_HAS_DEATH_TEST && defined(__cpp_if_constexpr)
1546-
EXPECT_DEATH(EXPECT_EQ(child->moo_int(), 0), "use-after-poison");
1547-
#endif
1548-
#endif
1544+
#endif // !PROTOBUF_ASAN
15491545
}
15501546

15511547
TEST(ArenaTest, CopyValuesWithinOneof) {

src/google/protobuf/port_def.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static_assert(PROTOBUF_GNUC_MIN(7, 3), "Protobuf only supports GCC 7.3 and newer
116116
#elif defined(_MSVC_LANG)
117117
static_assert(PROTOBUF_MSC_VER_MIN(1910), "Protobuf only supports MSVC 2017 and newer.");
118118
#endif
119-
static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and newer.");
119+
static_assert(PROTOBUF_CPLUSPLUS_MIN(201703L),
120+
"Protobuf only supports C++17 and newer.");
120121

121122
// Check minimum Abseil version.
122123
#if defined(ABSL_LTS_RELEASE_VERSION) && defined(ABSL_LTS_RELEASE_PATCH_LEVEL)
@@ -371,7 +372,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
371372
#ifdef PROTOBUF_NODISCARD
372373
#error PROTOBUF_NODISCARD was previously defined
373374
#endif
374-
#if ABSL_HAVE_CPP_ATTRIBUTE(nodiscard) && PROTOBUF_CPLUSPLUS_MIN(201703L)
375+
#if ABSL_HAVE_CPP_ATTRIBUTE(nodiscard)
375376
#define PROTOBUF_NODISCARD [[nodiscard]]
376377
#elif ABSL_HAVE_ATTRIBUTE(warn_unused_result) || defined(__GNUC__)
377378
#define PROTOBUF_NODISCARD __attribute__((warn_unused_result))
@@ -615,8 +616,7 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
615616
#ifdef PROTOBUF_UNUSED
616617
#error PROTOBUF_UNUSED was previously defined
617618
#endif
618-
#if ABSL_HAVE_CPP_ATTRIBUTE(maybe_unused) || \
619-
(PROTOBUF_MSC_VER_MIN(1911) && PROTOBUF_CPLUSPLUS_MIN(201703L))
619+
#if ABSL_HAVE_CPP_ATTRIBUTE(maybe_unused) || (PROTOBUF_MSC_VER_MIN(1911))
620620
#define PROTOBUF_UNUSED [[maybe_unused]]
621621
#elif ABSL_HAVE_ATTRIBUTE(unused) || defined(__GNUC__)
622622
#define PROTOBUF_UNUSED __attribute__((__unused__))

src/google/protobuf/proto3_arena_unittest.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,7 @@ TEST(Proto3ArenaTest, CheckOneofMessageFieldIsCleared) {
289289

290290
#ifndef PROTOBUF_ASAN
291291
EXPECT_EQ(child->bb(), 0);
292-
#else
293-
#if GTEST_HAS_DEATH_TEST && defined(__cpp_if_constexpr)
294-
EXPECT_DEATH(EXPECT_EQ(child->bb(), 100), "use-after-poison");
295-
#endif
296-
#endif
292+
#endif // !PROTOBUF_ASAN
297293
}
298294

299295
TEST(Proto3OptionalTest, OptionalFieldDescriptor) {

src/google/protobuf/reflection_visit_field_info.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,13 @@ struct RepeatedGroupDynamicExtensionInfo
11371137
// users from a similar dispatch without creating KeyInfo or ValueInfo per type.
11381138
template <FieldDescriptor::CppType cpp_type, typename T>
11391139
inline size_t MapPrimitiveFieldByteSize(FieldDescriptor::Type type, T value) {
1140+
// There is a bug in GCC 9.5 where if-constexpr arguments are not understood
1141+
// if encased in a switch statement. A reproduction of the bug can be found
1142+
// at: https://godbolt.org/z/qo51cKe7b
1143+
// This is fixed in GCC 10.1+.
1144+
(void)type; // Suppress -Wunused-but-set-parameter
1145+
(void)value; // Suppress -Wunused-but-set-parameter
1146+
11401147
if constexpr (cpp_type == FieldDescriptor::CPPTYPE_INT32) {
11411148
static_assert(std::is_same_v<T, int32_t>, "type mismatch");
11421149
switch (type) {

src/google/protobuf/reflection_visit_fields_test.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void MutateNothingByVisit(Message& message) {
172172
}
173173
} else {
174174
for (auto& it : info.Mutable()) {
175-
it = it;
175+
it = *&it; // Avoid -Wself-assign.
176176
}
177177
}
178178
} else {
@@ -207,6 +207,12 @@ TEST_P(VisitFieldsTest, MutateNothingByVisitIdempotent) {
207207

208208
template <typename InfoT>
209209
inline size_t MapKeyByteSizeLong(FieldDescriptor::Type type, InfoT info) {
210+
// There is a bug in GCC 9.5 where if-constexpr arguments are not understood
211+
// if passed into a helper function. A reproduction of the bug can be found
212+
// at: https://godbolt.org/z/65qW3vGhP
213+
// This is fixed in GCC 10.1+.
214+
(void)type; // Suppress -Wunused-but-set-parameter
215+
210216
if constexpr (info.cpp_type == FieldDescriptor::CPPTYPE_STRING) {
211217
return WireFormatLite::StringSize(info.Get());
212218
} else {
@@ -216,6 +222,12 @@ inline size_t MapKeyByteSizeLong(FieldDescriptor::Type type, InfoT info) {
216222

217223
template <typename InfoT>
218224
inline size_t MapValueByteSizeLong(FieldDescriptor::Type type, InfoT info) {
225+
// There is a bug in GCC 9.5 where if-constexpr arguments are not understood
226+
// if passed into a helper function. A reproduction of the bug can be found
227+
// at: https://godbolt.org/z/65qW3vGhP
228+
// This is fixed in GCC 10.1+.
229+
(void)type; // Suppress -Wunused-but-set-parameter
230+
219231
if constexpr (info.cpp_type == FieldDescriptor::CPPTYPE_STRING) {
220232
return WireFormatLite::StringSize(info.Get());
221233
} else if constexpr (info.cpp_type == FieldDescriptor::CPPTYPE_MESSAGE) {

0 commit comments

Comments
 (0)