diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index 4284cec120e74..24e48e55e7336 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -67,6 +67,9 @@ absl::flat_hash_map CommonVars( {"hrule_thick", kThickSeparator}, {"hrule_thin", kThinSeparator}, + {"nullable", "PROTOBUF_NULLABLE"}, + {"nonnull", "PROTOBUF_NONNULL"}, + // Warning: there is some clever naming/splitting here to avoid extract // script rewrites. The names of these variables must not be things that // the extract script will rewrite. That's why we use "CHK" (for example) diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 8225445450dc8..30c2e396ef14c 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -902,6 +902,14 @@ namespace internal { #define PROTOBUF_DEPRECATE_AND_INLINE() [[deprecated]] #endif +#ifdef PROTOBUF_NONNULL +#error PROTOBUF_NONNULL was previously defined +#endif +#ifndef PROTOBUF_NONNULL +#define PROTOBUF_NONNULL +#define PROTOBUF_NULLABLE +#endif + namespace google { namespace protobuf { namespace internal { diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 0fb70db0a97c8..60a96fce1de83 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -63,6 +63,8 @@ #undef PROTOBUF_TC_PARAM_DECL #undef PROTOBUF_DEBUG #undef PROTOBUF_NO_THREADLOCAL +#undef PROTOBUF_NONNULL +#undef PROTOBUF_NULLABLE #ifdef PROTOBUF_FUTURE_BREAKING_CHANGES #undef PROTOBUF_FUTURE_BREAKING_CHANGES