Skip to content

Commit 22d9a03

Browse files
protobuf-github-botzhangskz
authored andcommitted
Omit the _raw_default_instance_ declaration when using DLL linkage.
In that mode we might not be able to make a `constexpr` pointer to the default instance. Omitting the declaration will only turn off an optimization, but the code will still be correct. Fixes #17303 PiperOrigin-RevId: 649160060
1 parent 7592817 commit 22d9a03

File tree

5 files changed

+13
-80
lines changed

5 files changed

+13
-80
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,18 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
19041904
$pbi$::ParseContext* ctx);
19051905
)cc");
19061906
}},
1907+
{"raw_default_instance",
1908+
[&] {
1909+
// We can't make a constexpr pointer to the global if we have DLL
1910+
// linkage so skip this. The fallback in
1911+
// `MessageLite::GetStrongPointerForType` will do the right thing in
1912+
// those platforms.
1913+
if (!options_.dllexport_decl.empty()) return;
1914+
p->Emit(R"cc(
1915+
static constexpr const void* _raw_default_instance_ =
1916+
&_$classname$_default_instance_;
1917+
)cc");
1918+
}},
19071919
{"decl_impl", [&] { GenerateImplDefinition(p); }},
19081920
{"split_friend",
19091921
[&] {
@@ -2043,8 +2055,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
20432055
$decl_data$;
20442056
$post_loop_handler$;
20452057
2046-
static constexpr const void* _raw_default_instance_ =
2047-
&_$classname$_default_instance_;
2058+
$raw_default_instance$;
20482059
20492060
friend class ::$proto_ns$::MessageLite;
20502061
friend class ::$proto_ns$::Arena;

src/google/protobuf/compiler/java/java_features.pb.h

Lines changed: 0 additions & 2 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: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/cpp_features.pb.h

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

src/google/protobuf/descriptor.pb.h

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

0 commit comments

Comments
 (0)