Fixed #3579 (object destroyed immediately:False positive & negative)

This commit is contained in:
seb777 2012-06-10 21:52:32 +02:00 committed by Daniel Marjamäki
parent c9cb492bc7
commit 5b763a9f0a
2 changed files with 32 additions and 8 deletions

View File

@ -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();

View File

@ -23,6 +23,7 @@
#include "token.h"
#include "settings.h"
#include "templatesimplifier.h"
#include "path.h"
#include <sstream>
#include <list>
@ -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() {