From d122b1c722dbe6768ba02c22399caf4a2f29fe56 Mon Sep 17 00:00:00 2001 From: Thomas Niederberger <781000+Niederb@users.noreply.github.com> Date: Fri, 23 Aug 2019 06:43:02 +0200 Subject: [PATCH] Fix issue with __declspec and final (#2107) * Add missing Qt macros Add two Qt macros that were missing * Fix issue with __declspec and final This change is a bit naive but it fixes the issues I was having when combining __declspec(dllexport) and final classes. Without the fix I get errors along the line of "The code 'class x final :' is not handled. You can use -I or --include to add handling of this code. " --- lib/tokenize.cpp | 8 +++++--- test/testgarbage.cpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ecb2a0dfd..43ce74237 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4345,6 +4345,10 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) if (mSettings->terminated()) return false; + // Remove __declspec() + simplifyDeclspec(); + validate(); + // Remove "inline", "register", and "restrict" simplifyKeyword(); @@ -4390,9 +4394,7 @@ bool Tokenizer::simplifyTokenList1(const char FileName[]) // remove calling conventions __cdecl, __stdcall.. simplifyCallingConvention(); - // Remove __declspec() - simplifyDeclspec(); - validate(); + // remove some unhandled macros in global scope removeMacrosInGlobalScope(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index d153b7513..4dd0c361d 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -45,6 +45,8 @@ private: settings.experimental = true; // don't freak out when the syntax is wrong + + TEST_CASE(final_class_x); TEST_CASE(wrong_syntax1); TEST_CASE(wrong_syntax2); TEST_CASE(wrong_syntax3); // #3544 @@ -298,6 +300,20 @@ private: return ""; } + + void final_class_x() { + + const char code[] = "class __declspec(dllexport) x final { };"; + { + errout.str(""); + Tokenizer tokenizer(&settings, this); + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + tokenizer.simplifyTokenList2(); + ASSERT_EQUALS("", errout.str()); + } + } + void wrong_syntax1() { { const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; @@ -328,6 +344,7 @@ private: ASSERT_THROW(checkCode(code), InternalError); } + void wrong_syntax3() { // #3544 const char code[] = "X #define\n" "{\n"