From 35e89279bc699401d6b6ecec529b912118e18792 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Mon, 13 Feb 2023 16:06:20 -0800 Subject: [PATCH] Work around errornous warning in gcc <= 12.2 gcc 12.[12] emits a -Wrestrict warning if compiled with -O2/-O3 and -std=c++20 enabled when assigning a string with a single character to a std::string. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 This is benign; disable this broken warning for up to 12.4. PiperOrigin-RevId: 509358966 --- src/google/protobuf/port_def.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index d87b6b9929..3283030c16 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -1027,6 +1027,13 @@ static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and // int index = ... // int value = vec[index]; #pragma GCC diagnostic ignored "-Wsign-conversion" +#if __GNUC__ == 12 && __GNUC_MINOR__ < 4 +// Wrong warning emitted when assigning a single char c-string to a std::string +// in c++20 mode and optimization on. +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105329 +// Planned to be fixed by 12.3 but widen window to 12.4. +#pragma GCC diagnostic ignored "-Wrestrict" +#endif #endif // __GNUC__ // Silence some MSVC warnings in all our code.