Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC-12: Compiler error with C++20 mode on char* + string. #4108

Closed
danakj opened this issue Jan 1, 2023 · 1 comment
Closed

GCC-12: Compiler error with C++20 mode on char* + string. #4108

danakj opened this issue Jan 1, 2023 · 1 comment

Comments

@danakj
Copy link

danakj commented Jan 1, 2023

Describe the issue

Compile error in gtest-all.cc with GCC-12 and C++20 mode.

Steps to reproduce the problem

There were no errors compiling with GCC-11, but with GCC-12 I get this error:

FAILED: third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o 
/usr/bin/g++-12  -I/home/runner/work/subspace/subspace/third_party/googletest/googletest/include -I/home/runner/work/subspace/subspace/third_party/googletest/googletest -O3 -DNDEBUG -Wall -Wshadow -Werror -Wno-error=dangling-else -DGTEST_HAS_PTHREAD=1 -fexceptions -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -std=c++20 -MD -MT third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o -MF third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o.d -o third_party/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o -c /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest-all.cc
In file included from /usr/include/c++/12/ios:40,
                 from /usr/include/c++/12/ostream:38,
                 from /usr/include/c++/12/bits/unique_ptr.h:41,
                 from /usr/include/c++/12/memory:76,
                 from /home/runner/work/subspace/subspace/third_party/googletest/googletest/include/gtest/gtest.h:57,
                 from /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest-all.cc:38:
In static member function ‘static constexpr std::char_traits<char>::char_type* std::char_traits<char>::copy(char_type*, const char_type*, std::size_t)’,
    inlined from ‘static constexpr void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_S_copy(_CharT*, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:423:21,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::_M_replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.tcc:532:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::replace(size_type, size_type, const _CharT*, size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:2171:19,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>& std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::insert(size_type, const _CharT*) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:1928:22,
    inlined from ‘constexpr std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&) [with _CharT = char; _Traits = char_traits<char>; _Alloc = allocator<char>]’ at /usr/include/c++/12/bits/basic_string.h:3541:36,
    inlined from ‘static std::string testing::internal::StreamingListener::UrlEncode(const char*)’ at /home/runner/work/subspace/subspace/third_party/googletest/googletest/src/gtest.cc:4882:27:
/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223[37](https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472#step:7:38)2036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]
  [43](https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472#step:7:44)1 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
      |                                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

Clearly 9223372036854775813 is a lot of bytes.

https://github.com/chromium/subspace/actions/runs/3814961661/jobs/6489651472 demonstrates the error.

chromium/subspace@ecded91 fixes the error.

-        result.append("%" + String::FormatByte(static_cast<unsigned char>(ch)));
+        result.push_back('%');
+        result.append(String::FormatByte(static_cast<unsigned char>(ch)));

What version of GoogleTest are you using?

googletest 1.11

What operating system and version are you using?

Ubuntu 22.04.1 LTS

What compiler and version are you using?

gcc 12.1.0
Compiling with -std=c++20

What build system are you using?

cmake on github actions

Additional context

No response

@danakj danakj changed the title GCC-12: GCC-12: Compiler error with C++20 mode on char + string. Jan 1, 2023
@danakj danakj changed the title GCC-12: Compiler error with C++20 mode on char + string. GCC-12: Compiler error with C++20 mode on char* + string. Jan 1, 2023
@derekmauro
Copy link
Member

A small reproduction is here: https://godbolt.org/z/Pe5aE59xG

I'm not sure how GCC managed to ship this in 12.1 and then didn't fix it for 12.2. It looks fixed in trunk though.

I'll add a workaround similar to your patch. Thanks.

gaspardpetit pushed a commit to eidosmontreal/googletest that referenced this issue Feb 24, 2023
Fixes google#4108

PiperOrigin-RevId: 499556061
Change-Id: I1cb1564f9b77e1825fddc9236965f4a3b661d96a
apazylbe added a commit to apazylbe/bigwheels that referenced this issue Jun 23, 2023
When building with PPX_BUILD_XR=0 and Release, warnings are
treated as errors, and googletest seems to have an issue
with C++20 and gcc12, and the repo contains a workaround
in a later version.
google/googletest#4108
apazylbe added a commit to apazylbe/bigwheels that referenced this issue Jun 23, 2023
When building with PPX_BUILD_XR=0 and Release, warnings are
treated as errors. Googletest seems to have an issue
with C++20 and gcc12. The repo contains a workaround
in a later version.
google/googletest#4108
apazylbe added a commit to apazylbe/bigwheels that referenced this issue Jun 23, 2023
When building with PPX_BUILD_XR=0 and Release, warnings are
treated as errors. Googletest seems to have an issue
with C++20 and gcc12. The repo contains a workaround
in a later version.
google/googletest#4108
Keenuts pushed a commit to google/bigwheels that referenced this issue Jun 27, 2023
When building with PPX_BUILD_XR=0 and Release, warnings are treated as
errors. Googletest seems to have an issue with C++20 and gcc12. The repo
contains a workaround in a later version.
google/googletest#4108
kunitoki pushed a commit to kunitoki/googletest that referenced this issue Nov 4, 2023
Fixes google#4108

PiperOrigin-RevId: 499556061
Change-Id: I1cb1564f9b77e1825fddc9236965f4a3b661d96a
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

No branches or pull requests

3 participants
@danakj @derekmauro and others