THRIFT-1276 Add thrift compiler option to suppress warnings about
Patch: Dave Watson
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1159593 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/globals.h b/compiler/cpp/src/globals.h
index b856a61..2b1865b 100644
--- a/compiler/cpp/src/globals.h
+++ b/compiler/cpp/src/globals.h
@@ -129,4 +129,13 @@
*/
extern int g_allow_neg_field_keys;
+/**
+ * Whether or not 64-bit constants will generate a warning.
+ *
+ * Some languages don't support 64-bit constants, but many do, so we can
+ * suppress this warning for projects that don't use any non-64-bit-safe
+ * languages.
+ */
+extern int g_allow_64bit_consts;
+
#endif
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index da86d0d..892ae20 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -157,6 +157,11 @@
int g_allow_neg_field_keys;
/**
+ * Whether or not 64-bit constants will generate a warning.
+ */
+int g_allow_64bit_consts = 0;
+
+/**
* Flags to control code generation
*/
bool gen_cpp = false;
@@ -647,6 +652,7 @@
fprintf(stderr, " --allow-neg-keys Allow negative field keys (Used to "
"preserve protocol\n");
fprintf(stderr, " compatibility with older .thrift files)\n");
+ fprintf(stderr, " --allow-64bit-consts Do not print warnings about using 64-bit constants\n");
fprintf(stderr, " --gen STR Generate code with a dynamically-registered generator.\n");
fprintf(stderr, " STR has the form language[:key1=val1[,key2,[key3=val3]]].\n");
fprintf(stderr, " Keys and values are options passed to the generator.\n");
@@ -980,6 +986,8 @@
gen_recurse = true;
} else if (strcmp(arg, "-allow-neg-keys") == 0) {
g_allow_neg_field_keys = true;
+ } else if (strcmp(arg, "-allow-64bit-consts") == 0) {
+ g_allow_64bit_consts = true;
} else if (strcmp(arg, "-gen") == 0) {
arg = argv[++i];
if (arg == NULL) {
diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy
index f50c1e2..c916604 100644
--- a/compiler/cpp/src/thrifty.yy
+++ b/compiler/cpp/src/thrifty.yy
@@ -618,7 +618,7 @@
pdebug("ConstValue => tok_int_constant");
$$ = new t_const_value();
$$->set_integer($1);
- if ($1 < INT32_MIN || $1 > INT32_MAX) {
+ if (!g_allow_64bit_consts && ($1 < INT32_MIN || $1 > INT32_MAX)) {
pwarning(1, "64-bit constant \"%"PRIi64"\" may not work in all languages.\n", $1);
}
}