Regarding c++ Protobuf compiler: Extra line needed between #include and #endif in generated .pb.h file

135 views
Skip to first unread message

Shivaji Sawant

unread,
Jan 26, 2020, 9:24:27 AM1/26/20
to Protocol Buffers
Hi,
I have a question regarding the file generated by c++ Protobuf compiler i.e *.pb.h file

Previously I was using Protobuf 2.3.0 and my generated .pb.h used to look like this (I'm pasting the last few lines of the .pb.h file):

.
.
.
template <>
inline const EnumDescriptor* GetEnumDescriptor< rwmp::SLNetSpace>() {
  return rwmp::SLNetSpace_descriptor();
}

}  // namespace google
}  // namespace protobuf
#endif  // SWIG

#endif  // PROTOBUF_abcd_2eproto__INCLUDED


Now I have upgraded my Protobuf to 3.11.0 and newer generated .pb.h  looks like this (last few lines of the .pb.h file):

.
.
.
template <>
inline const EnumDescriptor* GetEnumDescriptor< ::rwmp::SLNetSpace>() {
  return ::rwmp::SLNetSpace_descriptor();
}

PROTOBUF_NAMESPACE_CLOSE

// @@protoc_insertion_point(global_scope)

#include <google/protobuf/port_undef.inc>
#endif  // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_abcd_2eproto

Now the problem is I want an empty line between #include and #endif
I don't want to do it manually and want to make changes in protobuf compiler code itself

The reason for this change is a compilation problem with GCC 8.2
Previously when I was using protobuf 2.3.0, my code used to compile without any warnings and now when using protobuf 3.11.0, I get following warnings
'warning: file "xyz.h" linemarker ignored due to incorrect nesting'
xyz.h is a file in which abcd.pb.h is included

I googled the above warning and found that there's a bug in GCC itself and is been solved but I don't want to update GCC to a newer version.
Here's a link discussing about the above bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83173
Due to this warning, GCC is also generating incorrect line mappings in the debug symbols.

Can someone help me in how can I patch Protobuf compiler 3.11.0 so that extra line is added between #include and #endif ?

Thanks in advance.

Reply all
Reply to author
Forward
0 new messages