From a145b4d58ad8e91933e6548128d83a18dff3bb9b Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Fri, 3 Apr 2009 17:29:25 +0000 Subject: [PATCH] THRIFT-423. -strict should turn omitted field ids into compile error Issue name says it all. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@761736 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/globals.h | 5 +++++ compiler/cpp/src/main.cc | 6 ++++++ compiler/cpp/src/thrifty.yy | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/compiler/cpp/src/globals.h b/compiler/cpp/src/globals.h index 3b9e4a48..b2041436 100644 --- a/compiler/cpp/src/globals.h +++ b/compiler/cpp/src/globals.h @@ -53,6 +53,11 @@ enum PARSE_MODE { PROGRAM = 2 }; +/** + * Strictness level + */ +extern int g_strict; + /** * The master program parse tree. This is accessed from within the parser code * to build up the program elements. diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc index 8a0bd68f..7a5d2d49 100644 --- a/compiler/cpp/src/main.cc +++ b/compiler/cpp/src/main.cc @@ -120,6 +120,11 @@ bool g_cpp_use_include_prefix = false; */ int g_debug = 0; +/** + * Strictness level + */ +int g_strict = 127; + /** * Warning level */ @@ -928,6 +933,7 @@ int main(int argc, char** argv) { } else if (strcmp(arg, "-nowarn") == 0) { g_warn = 0; } else if (strcmp(arg, "-strict") == 0) { + g_strict = 255; g_warn = 2; } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "-verbose") == 0 ) { g_verbose = 1; diff --git a/compiler/cpp/src/thrifty.yy b/compiler/cpp/src/thrifty.yy index c0505905..bf5408e3 100644 --- a/compiler/cpp/src/thrifty.yy +++ b/compiler/cpp/src/thrifty.yy @@ -848,6 +848,10 @@ Field: pdebug("tok_int_constant : Field -> FieldType tok_identifier"); if ($2 < 0) { pwarning(1, "No field key specified for %s, resulting protocol may have conflicts or not be backwards compatible!\n", $5); + if (g_strict >= 192) { + yyerror("Implicit field keys are deprecated and not allowed with -strict"); + exit(1); + } } $$ = new t_field($4, $5, $2); $$->set_req($3); -- 2.17.1