aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/cpp/cpp_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_file.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_file.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc
index aea3a4b2..f88d63fc 100644
--- a/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -128,7 +128,14 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
// Open namespace.
GenerateNamespaceOpeners(printer);
- printer->Print("\n");
+ // Forward-declare the BuildDescriptors function, so that we can declare it
+ // to be a friend of each class.
+ printer->Print(
+ "\n"
+ "// Internal implementation detail -- do not call this.\n"
+ "void $builddescriptorsname$();\n"
+ "\n",
+ "builddescriptorsname", GlobalBuildDescriptorsName(file_->name()));
// Generate forward declarations of classes.
for (int i = 0; i < file_->message_type_count(); i++) {
@@ -302,6 +309,9 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// time, because every message has a statically-initialized default instance,
// and the constructor for a message class accesses its descriptor. See the
// constructor and the descriptor() method of message classes.
+ //
+ // We also construct the reflection object for each class inside
+ // BuildDescriptors().
printer->Print(
"\n"
"void $builddescriptorsname$() {\n"