Skip to content

Commit c00fd25

Browse files
derekmaurocopybara-github
authored andcommitted
Require C++17
Policy information: https://opensource.google/documentation/policies/cplusplus-support#c_language_standard https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md Some small fixes are included for C++17 compatibility. We had no tests for MSVC C++17 or C++20, so those tests that failed and had no obvious fix are disabled and a tracking bug has been filed. PiperOrigin-RevId: 726090558 Change-Id: I4d37d47e87c11f85bfd572deb10f67ca3eb2a9b5
1 parent 4a00a24 commit c00fd25

File tree

9 files changed

+95
-57
lines changed

9 files changed

+95
-57
lines changed

ci/linux-presubmit.sh

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,50 +39,68 @@ if [[ -z ${GTEST_ROOT:-} ]]; then
3939
fi
4040

4141
if [[ -z ${STD:-} ]]; then
42-
STD="c++14 c++17 c++20"
42+
STD="c++17 c++20"
4343
fi
4444

45-
# Test the CMake build
46-
for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do
47-
for cmake_off_on in OFF ON; do
48-
time docker run \
49-
--volume="${GTEST_ROOT}:/src:ro" \
50-
--tmpfs="/build:exec" \
51-
--workdir="/build" \
52-
--rm \
53-
--env="CC=${cc}" \
54-
--env=CXXFLAGS="-Werror -Wdeprecated" \
55-
${LINUX_LATEST_CONTAINER} \
56-
/bin/bash -c "
57-
cmake /src \
58-
-DCMAKE_CXX_STANDARD=14 \
59-
-Dgtest_build_samples=ON \
60-
-Dgtest_build_tests=ON \
61-
-Dgmock_build_tests=ON \
62-
-Dcxx_no_exception=${cmake_off_on} \
63-
-Dcxx_no_rtti=${cmake_off_on} && \
64-
make -j$(nproc) && \
65-
ctest -j$(nproc) --output-on-failure"
66-
done
45+
# Test CMake + GCC
46+
for cmake_off_on in OFF ON; do
47+
time docker run \
48+
--volume="${GTEST_ROOT}:/src:ro" \
49+
--tmpfs="/build:exec" \
50+
--workdir="/build" \
51+
--rm \
52+
--env="CC=/usr/local/bin/gcc" \
53+
--env=CXXFLAGS="-Werror -Wdeprecated" \
54+
${LINUX_LATEST_CONTAINER} \
55+
/bin/bash -c "
56+
cmake /src \
57+
-DCMAKE_CXX_STANDARD=17 \
58+
-Dgtest_build_samples=ON \
59+
-Dgtest_build_tests=ON \
60+
-Dgmock_build_tests=ON \
61+
-Dcxx_no_exception=${cmake_off_on} \
62+
-Dcxx_no_rtti=${cmake_off_on} && \
63+
make -j$(nproc) && \
64+
ctest -j$(nproc) --output-on-failure"
65+
done
66+
67+
# Test CMake + Clang
68+
for cmake_off_on in OFF ON; do
69+
time docker run \
70+
--volume="${GTEST_ROOT}:/src:ro" \
71+
--tmpfs="/build:exec" \
72+
--workdir="/build" \
73+
--rm \
74+
--env="CC=/opt/llvm/clang/bin/clang" \
75+
--env=CXXFLAGS="-Werror -Wdeprecated --gcc-toolchain=/usr/local" \
76+
${LINUX_LATEST_CONTAINER} \
77+
/bin/bash -c "
78+
cmake /src \
79+
-DCMAKE_CXX_STANDARD=17 \
80+
-Dgtest_build_samples=ON \
81+
-Dgtest_build_tests=ON \
82+
-Dgmock_build_tests=ON \
83+
-Dcxx_no_exception=${cmake_off_on} \
84+
-Dcxx_no_rtti=${cmake_off_on} && \
85+
make -j$(nproc) && \
86+
ctest -j$(nproc) --output-on-failure"
6787
done
6888

6989
# Do one test with an older version of GCC
70-
# TODO(googletest-team): This currently uses Bazel 5. When upgrading to a
71-
# version of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test
72-
# coverage for the old WORKSPACE dependency management.
7390
time docker run \
7491
--volume="${GTEST_ROOT}:/src:ro" \
7592
--workdir="/src" \
7693
--rm \
7794
--env="CC=/usr/local/bin/gcc" \
78-
--env="BAZEL_CXXOPTS=-std=c++14" \
95+
--env="BAZEL_CXXOPTS=-std=c++17" \
7996
${LINUX_GCC_FLOOR_CONTAINER} \
8097
/usr/local/bin/bazel test ... \
8198
--copt="-Wall" \
8299
--copt="-Werror" \
83100
--copt="-Wuninitialized" \
84101
--copt="-Wundef" \
85102
--copt="-Wno-error=pragmas" \
103+
--enable_bzlmod=false \
86104
--features=external_include_paths \
87105
--keep_going \
88106
--show_timestamps \

ci/macos-presubmit.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
set -euox pipefail
3333

34+
# Use Xcode 16.0
35+
sudo xcode-select -s /Applications/Xcode_16.0.app/Contents/Developer
36+
3437
if [[ -z ${GTEST_ROOT:-} ]]; then
3538
GTEST_ROOT="$(realpath $(dirname ${0})/..)"
3639
fi
@@ -40,20 +43,20 @@ for cmake_off_on in OFF ON; do
4043
BUILD_DIR=$(mktemp -d build_dir.XXXXXXXX)
4144
cd ${BUILD_DIR}
4245
time cmake ${GTEST_ROOT} \
43-
-DCMAKE_CXX_STANDARD=14 \
46+
-DCMAKE_CXX_STANDARD=17 \
4447
-Dgtest_build_samples=ON \
4548
-Dgtest_build_tests=ON \
4649
-Dgmock_build_tests=ON \
4750
-Dcxx_no_exception=${cmake_off_on} \
4851
-Dcxx_no_rtti=${cmake_off_on}
49-
time make
52+
time make -j$(nproc)
5053
time ctest -j$(nproc) --output-on-failure
5154
done
5255

5356
# Test the Bazel build
5457

5558
# If we are running on Kokoro, check for a versioned Bazel binary.
56-
KOKORO_GFILE_BAZEL_BIN="bazel-7.0.0-darwin-x86_64"
59+
KOKORO_GFILE_BAZEL_BIN="bazel-8.0.0-darwin-x86_64"
5760
if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then
5861
BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}"
5962
chmod +x ${BAZEL_BIN}
@@ -67,7 +70,7 @@ for absl in 0 1; do
6770
--copt="-Wall" \
6871
--copt="-Werror" \
6972
--copt="-Wundef" \
70-
--cxxopt="-std=c++14" \
73+
--cxxopt="-std=c++17" \
7174
--define="absl=${absl}" \
7275
--enable_bzlmod=true \
7376
--features=external_include_paths \

ci/windows-presubmit.bat

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SETLOCAL ENABLEDELAYEDEXPANSION
22

3-
SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-7.0.0-windows-x86_64.exe
3+
SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-8.0.0-windows-x86_64.exe
44

55
SET PATH=C:\Python34;%PATH%
66
SET BAZEL_PYTHON=C:\python34\python.exe
@@ -11,21 +11,18 @@ SET CTEST_OUTPUT_ON_FAILURE=1
1111
SET CMAKE_BUILD_PARALLEL_LEVEL=16
1212
SET CTEST_PARALLEL_LEVEL=16
1313

14-
IF EXIST git\googletest (
15-
CD git\googletest
16-
) ELSE IF EXIST github\googletest (
17-
CD github\googletest
18-
)
19-
14+
SET GTEST_ROOT=%~dp0\..
2015
IF %errorlevel% neq 0 EXIT /B 1
2116

2217
:: ----------------------------------------------------------------------------
2318
:: CMake
24-
MKDIR cmake_msvc2022
25-
CD cmake_msvc2022
19+
SET CMAKE_BUILD_PATH=cmake_msvc2022
20+
MKDIR %CMAKE_BUILD_PATH%
21+
CD %CMAKE_BUILD_PATH%
2622

27-
%CMAKE_BIN% .. ^
23+
%CMAKE_BIN% %GTEST_ROOT% ^
2824
-G "Visual Studio 17 2022" ^
25+
-DCMAKE_CXX_STANDARD=17 ^
2926
-DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^
3027
-DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^
3128
-DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^
@@ -40,8 +37,8 @@ IF %errorlevel% neq 0 EXIT /B 1
4037
%CTEST_BIN% -C Debug --timeout 600
4138
IF %errorlevel% neq 0 EXIT /B 1
4239

43-
CD ..
44-
RMDIR /S /Q cmake_msvc2022
40+
CD %GTEST_ROOT%
41+
RMDIR /S /Q %CMAKE_BUILD_PATH%
4542

4643
:: ----------------------------------------------------------------------------
4744
:: Bazel
@@ -50,11 +47,26 @@ RMDIR /S /Q cmake_msvc2022
5047
:: because of Windows limitations on path length.
5148
:: --output_user_root=C:\tmp causes Bazel to use a shorter path.
5249
SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community
50+
51+
:: C++17
52+
%BAZEL_EXE% ^
53+
--output_user_root=C:\tmp ^
54+
test ... ^
55+
--compilation_mode=dbg ^
56+
--copt=/std:c++17 ^
57+
--copt=/WX ^
58+
--enable_bzlmod=true ^
59+
--keep_going ^
60+
--test_output=errors ^
61+
--test_tag_filters=-no_test_msvc2017
62+
IF %errorlevel% neq 0 EXIT /B 1
63+
64+
:: C++20
5365
%BAZEL_EXE% ^
5466
--output_user_root=C:\tmp ^
5567
test ... ^
5668
--compilation_mode=dbg ^
57-
--copt=/std:c++14 ^
69+
--copt=/std:c++20 ^
5870
--copt=/WX ^
5971
--enable_bzlmod=true ^
6072
--keep_going ^

googlemock/test/gmock-actions_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ TEST(TypeTraits, IsInvocableRV) {
222222
// In C++17 and above, where it's guaranteed that functions can return
223223
// non-moveable objects, everything should work fine for non-moveable rsult
224224
// types too.
225-
#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
226-
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
225+
// TODO(b/396121064) - Fix this test under MSVC
226+
#ifndef _MSC_VER
227227
{
228228
struct NonMoveable {
229229
NonMoveable() = default;
@@ -244,7 +244,7 @@ TEST(TypeTraits, IsInvocableRV) {
244244
static_assert(!internal::is_callable_r<int, Callable>::value);
245245
static_assert(!internal::is_callable_r<NonMoveable, Callable, int>::value);
246246
}
247-
#endif // C++17 and above
247+
#endif // _MSC_VER
248248

249249
// Nothing should choke when we try to call other arguments besides directly
250250
// callable objects, but they should not show up as callable.

googlemock/test/gmock-spec-builders_test.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,9 +804,8 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
804804
"to be called at least once");
805805
}
806806

807-
#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
808-
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
809-
807+
// TODO(b/396121064) - Fix this test under MSVC
808+
#ifndef _MSC_VER
810809
// It should be possible to return a non-moveable type from a mock action in
811810
// C++17 and above, where it's guaranteed that such a type can be initialized
812811
// from a prvalue returned from a function.
@@ -847,7 +846,7 @@ TEST(ExpectCallTest, NonMoveableType) {
847846
EXPECT_EQ(17, mock.AsStdFunction()().x);
848847
}
849848

850-
#endif // C++17 and above
849+
#endif // _MSC_VER
851850

852851
// Tests that the n-th action is taken for the n-th matching
853852
// invocation.

googletest/cmake/internal_utils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function(cxx_library_with_type name type cxx_flags)
195195
target_link_libraries(${name} PUBLIC Threads::Threads)
196196
endif()
197197

198-
target_compile_features(${name} PUBLIC cxx_std_14)
198+
target_compile_features(${name} PUBLIC cxx_std_17)
199199
endfunction()
200200

201201
########################################################################

googletest/include/gtest/internal/gtest-port.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@
275275
#endif
276276

277277
#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \
278-
GTEST_INTERNAL_CPLUSPLUS_LANG < 201402L
279-
#error C++ versions less than C++14 are not supported.
278+
GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
279+
#error C++ versions less than C++17 are not supported.
280280
#endif
281281

282282
// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include.

googletest/test/googletest-printers-test.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ class UnprintableTemplateInGlobal {
121121
// A user-defined streamable type in the global namespace.
122122
class StreamableInGlobal {
123123
public:
124+
StreamableInGlobal() = default;
125+
StreamableInGlobal(const StreamableInGlobal&) = default;
126+
StreamableInGlobal& operator=(const StreamableInGlobal&) = default;
124127
virtual ~StreamableInGlobal() = default;
125128
};
126129

@@ -572,14 +575,17 @@ TEST(PrintU8StringTest, Null) {
572575
}
573576

574577
// Tests that u8 strings are escaped properly.
578+
// TODO(b/396121064) - Fix this test under MSVC
579+
#ifndef _MSC_VER
575580
TEST(PrintU8StringTest, EscapesProperly) {
576581
const char8_t* p = u8"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
577582
EXPECT_EQ(PrintPointer(p) +
578583
" pointing to u8\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
579584
"hello \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
580585
Print(p));
581586
}
582-
#endif
587+
#endif // _MSC_VER
588+
#endif // __cpp_lib_char8_t
583589

584590
// const char16_t*.
585591
TEST(PrintU16StringTest, Const) {

googletest/test/googletest-setuptestsuite-test_.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131

3232
class SetupFailTest : public ::testing::Test {
3333
protected:
34-
static void SetUpTestSuite() { ASSERT_EQ("", "SET_UP_FAIL"); }
34+
static void SetUpTestSuite() { ASSERT_STREQ("", "SET_UP_FAIL"); }
3535
};
3636

3737
TEST_F(SetupFailTest, NoopPassingTest) {}
3838

3939
class TearDownFailTest : public ::testing::Test {
4040
protected:
41-
static void TearDownTestSuite() { ASSERT_EQ("", "TEAR_DOWN_FAIL"); }
41+
static void TearDownTestSuite() { ASSERT_STREQ("", "TEAR_DOWN_FAIL"); }
4242
};
4343

4444
TEST_F(TearDownFailTest, NoopPassingTest) {}

0 commit comments

Comments
 (0)