From 5b1b845750647b91e44264c783f15ad514b2e389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 20 Mar 2010 08:03:18 +0100 Subject: [PATCH] Fixed #1504 (False positive: Cppcheck incorrectly reports that extern variable is not initialized) --- lib/tokenize.cpp | 6 ++++++ test/testtokenize.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 0456d017b..e94b51ce1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4333,6 +4333,12 @@ void Tokenizer::unsignedint() continue; } + if (Token::Match(tok->previous(), "extern unsigned|signed *| %var% [;[]")) + { + tok->str("int"); + continue; + } + // signed int a; -> int a; if (Token::Match(tok, "signed %type% %var% [;,=)]")) { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 252802916..b25c30827 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -2734,6 +2734,12 @@ private: ASSERT_EQUALS(code2, tokenizeAndStringify(code1)); } + // "extern unsigned x;" => "extern int x;" + { + const char code1[] = "; extern unsigned x;"; + const char code2[] = "; extern int x ;"; + ASSERT_EQUALS(code2, tokenizeAndStringify(code1)); + } } void unsigned2()