From 5b763a9f0a12a5f96faa1803ee49f8f67dee9b7a Mon Sep 17 00:00:00 2001 From: seb777 Date: Sun, 10 Jun 2012 21:52:32 +0200 Subject: [PATCH] Fixed #3579 (object destroyed immediately:False positive & negative) --- lib/tokenize.cpp | 11 ++++++++++- test/testsimplifytokens.cpp | 29 ++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 040ebc7ff..b778727cf 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8139,9 +8139,18 @@ void Tokenizer::simplifyAttribute() } // Remove "volatile", "inline", "register", and "restrict" +// "restrict" keyword +// - New to 1999 ANSI/ISO C standard +// - Not in C++ standard yet void Tokenizer::simplifyKeyword() { - static const char pattern[] = "volatile|inline|__inline|__forceinline|register|restrict|__restrict|__restrict__"; + const char *pattern; + + if (_settings->standards.c99) + pattern = "volatile|inline|__inline|__forceinline|register|restrict|__restrict|__restrict__"; + else + pattern = "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__"; + for (Token *tok = list.front(); tok; tok = tok->next()) { while (Token::Match(tok, pattern)) { tok->deleteThis(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b52084eaa..7da778720 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -23,6 +23,7 @@ #include "token.h" #include "settings.h" #include "templatesimplifier.h" +#include "path.h" #include #include @@ -436,6 +437,20 @@ private: std::string tok(const std::string& code, bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { return tok(code.c_str(), simplify, type); } + std::string tok(const char code[], const char filename[]) { + errout.str(""); + + Settings settings; + if (Path::isC(filename)) + settings.standards.c99 = true; + Tokenizer tokenizer(&settings, this); + + std::istringstream istr(code); + tokenizer.tokenize(istr, filename); + tokenizer.simplifyTokenList(); + + return tokenizer.tokens()->stringifyList(0, false); + } void simplifyTokenList1() { @@ -7421,13 +7436,13 @@ private: ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true)); - ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", true)); - ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", true)); - ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * __restrict__ a, float * __restrict__ b);", true)); - ASSERT_EQUALS("int * p ;", tok("int * restrict p;", true)); - ASSERT_EQUALS("int * * p ;", tok("int * restrict * p;", true)); - ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * restrict a, float * restrict b);", true)); - ASSERT_EQUALS("int * p ;", tok("typedef int * __restrict__ rint; rint p;", true)); + ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c")); + ASSERT_EQUALS("int * * p ;", tok("int * __restrict__ * p;", "test.c")); + ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * __restrict__ a, float * __restrict__ b);", "test.c")); + ASSERT_EQUALS("int * p ;", tok("int * restrict p;", "test.c")); + ASSERT_EQUALS("int * * p ;", tok("int * restrict * p;", "test.c")); + ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * restrict a, float * restrict b);", "test.c")); + ASSERT_EQUALS("int * p ;", tok("typedef int * __restrict__ rint; rint p;", "test.c")); } void simplifyCallingConvention() {