Skip to content

Commit a611692

Browse files
committed
Fix #14576 (aligned_storage)
1 parent d657994 commit a611692

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,6 +5998,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
59985998
// Link < with >
59995999
createLinks2();
60006000

6001+
// Handle std::aligned_storage<...>
6002+
simplifyAlignedStorage();
6003+
60016004
// Mark C++ casts
60026005
markCppCasts();
60036006

@@ -11159,6 +11162,54 @@ void Tokenizer::simplifyNamespaceAliases()
1115911162
}
1116011163
}
1116111164

11165+
void Tokenizer::simplifyAlignedStorage()
11166+
{
11167+
if (!isCPP())
11168+
return;
11169+
11170+
const Standards::cppstd_t std = mSettings.standards.cpp;
11171+
if (std < Standards::CPP11 || std >= Standards::CPP23)
11172+
return;
11173+
11174+
for (Token *tok = list.front(); tok; tok = tok->next()) {
11175+
if (!Token::simpleMatch(tok, "aligned_storage <"))
11176+
continue;
11177+
11178+
tok = tok->next();
11179+
const Token *end = tok->link();
11180+
tok = tok->next();
11181+
11182+
if (!tok)
11183+
break;
11184+
11185+
if (!end)
11186+
continue;
11187+
11188+
for (; tok != end; tok = tok->next()) {
11189+
if (Token::simpleMatch(tok, ",")) {
11190+
tok = tok->next();
11191+
break;
11192+
}
11193+
11194+
if (Token::Match(tok, "(|<"))
11195+
tok = tok->link();
11196+
}
11197+
11198+
std::string str;
11199+
for (; tok != end; tok = tok->next()) {
11200+
str += " " + tok->str();
11201+
}
11202+
11203+
str = str.substr(1);
11204+
11205+
if (!Token::Match(tok, "> :: type %name%"))
11206+
continue;
11207+
11208+
tok = tok->tokAt(3);
11209+
tok->addAttributeAlignas(str);
11210+
}
11211+
}
11212+
1116211213
void Tokenizer::setDirectives(std::list<Directive> directives)
1116311214
{
1116411215
mDirectives = std::move(directives);

lib/tokenize.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ class CPPCHECKLIB Tokenizer {
528528
*/
529529
void simplifyNamespaceAliases();
530530

531+
/**
532+
* Handle std::aligned_storage<...>
533+
*/
534+
void simplifyAlignedStorage();
535+
531536
/**
532537
* Convert C++17 style nested namespace to older style
533538
*/

0 commit comments

Comments
 (0)