Skip to content

Commit e15326b

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Add a workaround for GCC constexpr bug
This turns the constexpr constructors into templates to silence errors when constexpr isn't valid. We are also switching to 12.2 for GCC/cmake tests to prevent regressions (9.5 and 13.1 are already tested by GCC/bazel tests). Fixes #12807 PiperOrigin-RevId: 532258101
1 parent 59a996b commit e15326b

File tree

6 files changed

+78
-2
lines changed

6 files changed

+78
-2
lines changed

.github/workflows/test_cpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ jobs:
234234
- name: Run tests
235235
uses: protocolbuffers/protobuf-ci/docker@v1
236236
with:
237-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:13.1-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
237+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:12.2-5.4.0-307caa02808127e49720f3e77d6a9f3b3ef5a915
238238
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
239239
entrypoint: bash
240240
command: >-

src/google/protobuf/compiler/cpp/message.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ std::vector<const FieldDescriptor*> SortFieldsByNumber(
156156
struct ExtensionRangeSorter {
157157
bool operator()(const Descriptor::ExtensionRange* left,
158158
const Descriptor::ExtensionRange* right) const {
159-
return left->start_number() < right->start_number();
159+
return left->start < right->start;
160160
}
161161
};
162162

@@ -1176,6 +1176,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
11761176
" ::$proto_ns$::internal::WireFormatLite::$val_wire_type$> "
11771177
"SuperType;\n"
11781178
" $classname$();\n"
1179+
// Templatize constexpr constructor as a workaround for a bug in gcc 12
1180+
// (warning in gcc 13).
1181+
" template <typename = void>\n"
11791182
" explicit PROTOBUF_CONSTEXPR $classname$(\n"
11801183
" ::$proto_ns$::internal::ConstantInitialized);\n"
11811184
" explicit $classname$(::$proto_ns$::Arena* arena);\n"
@@ -1269,6 +1272,9 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
12691272
format("~$classname$() override;\n");
12701273
}
12711274
format(
1275+
// Templatize constexpr constructor as a workaround for a bug in gcc 12
1276+
// (warning in gcc 13).
1277+
"template<typename = void>\n"
12721278
"explicit PROTOBUF_CONSTEXPR "
12731279
"$classname$(::$proto_ns$::internal::ConstantInitialized);\n"
12741280
"\n"
@@ -2526,6 +2532,9 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
25262532

25272533
if (IsMapEntryMessage(descriptor_) || !HasImplData(descriptor_, options_)) {
25282534
p->Emit(R"cc(
2535+
//~ Templatize constexpr constructor as a workaround for a bug in gcc 12
2536+
//~ (warning in gcc 13).
2537+
template <typename>
25292538
$constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized) {}
25302539
)cc");
25312540
return;
@@ -2604,6 +2613,9 @@ void MessageGenerator::GenerateConstexprConstructor(io::Printer* p) {
26042613
}},
26052614
},
26062615
R"cc(
2616+
//~ Templatize constexpr constructor as a workaround for a bug in gcc 12
2617+
//~ (warning in gcc 13).
2618+
template <typename>
26072619
$constexpr$ $classname$::$classname$(::_pbi::ConstantInitialized)
26082620
: _impl_{$init_body$} {}
26092621
)cc");

src/google/protobuf/compiler/plugin.pb.cc

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/plugin.pb.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/descriptor.pb.cc

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)