diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 94cabaad9..f17408b7b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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 keywords = { "inline" , "_inline" diff --git a/lib/tokenize.h b/lib/tokenize.h index 23f57b2a5..35be9b7da 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -692,6 +692,9 @@ private: */ void simplifyCppcheckAttribute(); + /** Remove alignas */ + void removeAlignas(); + /** * Remove keywords "volatile", "inline", "register", and "restrict" */ diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a6ce6716e..38243ff39 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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)