[C++] Static assert on Flatbuffers Version (#7203)
* Static assert on Flatbuffers Version * add comment
This commit is contained in:
parent
59e9713081
commit
0da6f94867
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace reflection {
|
||||
|
||||
struct Type;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
namespace Sample {
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/flatc.h"
|
||||
|
@ -199,6 +201,25 @@ class CppGenerator : public BaseGenerator {
|
|||
for (auto kw = keywords; *kw; kw++) keywords_.insert(*kw);
|
||||
}
|
||||
|
||||
// Adds code to check that the included flatbuffers.h is of the same version
|
||||
// as the generated code. This check currently looks for exact version match,
|
||||
// as we would guarantee that they are compatible, but in theory a newer
|
||||
// version of flatbuffers.h should work with a old code gen if we do proper
|
||||
// backwards support.
|
||||
void GenFlatbuffersVersionCheck() {
|
||||
code_ +=
|
||||
"// Ensure the included flatbuffers.h is the same version as when this "
|
||||
"file was";
|
||||
code_ += "// generated, otherwise it may not be compatible.";
|
||||
code_ += "static_assert(FLATBUFFERS_VERSION_MAJOR == " +
|
||||
std::to_string(FLATBUFFERS_VERSION_MAJOR) + " &&";
|
||||
code_ += " FLATBUFFERS_VERSION_MINOR == " +
|
||||
std::to_string(FLATBUFFERS_VERSION_MINOR) + " &&";
|
||||
code_ += " FLATBUFFERS_VERSION_REVISION == " +
|
||||
std::to_string(FLATBUFFERS_VERSION_REVISION) + ",";
|
||||
code_ += " \"Non-compatible flatbuffers version included\");";
|
||||
}
|
||||
|
||||
void GenIncludeDependencies() {
|
||||
int num_includes = 0;
|
||||
if (opts_.generate_object_based_api) {
|
||||
|
@ -285,6 +306,8 @@ class CppGenerator : public BaseGenerator {
|
|||
|
||||
code_ += "#include \"flatbuffers/flatbuffers.h\"";
|
||||
code_ += "";
|
||||
GenFlatbuffersVersionCheck();
|
||||
code_ += "";
|
||||
|
||||
SetNameSpace(struct_def.defined_namespace);
|
||||
auto name = Name(struct_def);
|
||||
|
@ -349,6 +372,8 @@ class CppGenerator : public BaseGenerator {
|
|||
code_ += "#include \"flatbuffers/flexbuffers.h\"";
|
||||
}
|
||||
code_ += "";
|
||||
GenFlatbuffersVersionCheck();
|
||||
code_ += "";
|
||||
|
||||
if (opts_.include_dependence_headers) { GenIncludeDependencies(); }
|
||||
GenExtraIncludes();
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
namespace Example {
|
||||
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/flexbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
|
||||
struct InParentNamespace;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace optional_scalars {
|
||||
|
||||
struct ScalarStuff;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
struct Attacker;
|
||||
struct AttackerBuilder;
|
||||
struct AttackerT;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace Evolution {
|
||||
namespace V1 {
|
||||
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace Evolution {
|
||||
namespace V2 {
|
||||
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
|
||||
struct MonsterExtra;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
namespace Example {
|
||||
|
||||
|
|
|
@ -7,6 +7,13 @@
|
|||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/flexbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
|
||||
struct InParentNamespace;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace NamespaceA {
|
||||
namespace NamespaceB {
|
||||
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace NamespaceA {
|
||||
|
||||
struct TableInFirstNS;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
#include "native_type_test_impl.h"
|
||||
|
||||
namespace Geometry {
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace optional_scalars {
|
||||
|
||||
struct ScalarStuff;
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
struct Attacker;
|
||||
struct AttackerBuilder;
|
||||
struct AttackerT;
|
||||
|
|
Loading…
Reference in New Issue