From b798b99777cf180c985e5080ddc93d3a15c2d4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 26 Apr 2021 11:43:49 +0200 Subject: [PATCH] Parser; do not remove alignof and alignas in the same way --- lib/tokenize.cpp | 6 ++---- test/testtokenize.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index dfc9a246c..e6b16cc24 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -11006,10 +11006,8 @@ void Tokenizer::removeAlignas() 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(); - } + if (Token::Match(tok, "[;{}] alignas (") && Token::Match(tok->linkAt(2), ") %name%")) + Token::eraseTokens(tok, tok->linkAt(2)->next()); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e7d8dc325..f2441e442 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -416,7 +416,8 @@ private: TEST_CASE(removeExtraTemplateKeywords); - TEST_CASE(removeAlignas); + TEST_CASE(removeAlignas1); + TEST_CASE(removeAlignas2); // Do not remove alignof in the same way TEST_CASE(simplifyCoroutines); @@ -6524,12 +6525,18 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringify(code2)); } - void removeAlignas() { + void removeAlignas1() { const char code[] = "alignas(float) unsigned char c[sizeof(float)];"; const char expected[] = "unsigned char c [ sizeof ( float ) ] ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } + void removeAlignas2() { // Do not remove alignas and alignof in the same way + const char code[] = "static_assert( alignof( VertexC ) == 4 );"; + const char expected[] = "static_assert ( alignof ( VertexC ) == 4 ) ;"; + ASSERT_EQUALS(expected, tokenizeAndStringify(code)); + } + void simplifyCoroutines() { Settings settings; settings.standards.cpp = Standards::CPP20;