Fixed #9415 (C++11: `alignas` not handled -> wrong code -> false negatives)
This commit is contained in:
parent
f62d9d5853
commit
11f828a669
|
@ -4781,6 +4781,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
|||
// Remove extra "template" tokens that are not used by cppcheck
|
||||
removeExtraTemplateKeywords();
|
||||
|
||||
removeAlignas();
|
||||
|
||||
// Bail out if code is garbage
|
||||
if (mTimerResults) {
|
||||
Timer t("Tokenizer::tokenize::findGarbageCode", mSettings->showtime, mTimerResults);
|
||||
|
@ -10905,6 +10907,19 @@ void Tokenizer::simplifyCPPAttribute()
|
|||
}
|
||||
}
|
||||
|
||||
void Tokenizer::removeAlignas()
|
||||
{
|
||||
if (!isCPP() || mSettings->standards.cpp < Standards::CPP11)
|
||||
return;
|
||||
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "alignas|alignof (")) {
|
||||
Token::eraseTokens(tok, tok->linkAt(1)->next());
|
||||
tok->deleteThis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const std::unordered_set<std::string> keywords = {
|
||||
"inline"
|
||||
, "_inline"
|
||||
|
|
|
@ -692,6 +692,9 @@ private:
|
|||
*/
|
||||
void simplifyCppcheckAttribute();
|
||||
|
||||
/** Remove alignas */
|
||||
void removeAlignas();
|
||||
|
||||
/**
|
||||
* Remove keywords "volatile", "inline", "register", and "restrict"
|
||||
*/
|
||||
|
|
|
@ -414,6 +414,8 @@ private:
|
|||
TEST_CASE(checkHeader1);
|
||||
|
||||
TEST_CASE(removeExtraTemplateKeywords);
|
||||
|
||||
TEST_CASE(removeAlignas);
|
||||
}
|
||||
|
||||
std::string tokenizeAndStringify(const char code[], bool expand = true, Settings::PlatformType platform = Settings::Native, const char* filename = "test.cpp", bool cpp11 = true) {
|
||||
|
@ -6497,6 +6499,12 @@ private:
|
|||
const char expected2[] = "GridView :: Codim < 0 > :: Iterator it ; it = gv . begin < 0 > ( ) ;";
|
||||
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2));
|
||||
}
|
||||
|
||||
void removeAlignas() {
|
||||
const char code[] = "alignas(float) unsigned char c[sizeof(float)];";
|
||||
const char expected[] = "unsigned char c [ sizeof ( float ) ] ;";
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue