Skip to content

Commit 04fda78

Browse files
committed
Fix #14576 (aligned_storage)
1 parent effb04e commit 04fda78

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6008,6 +6008,9 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
60086008
// Link < with >
60096009
createLinks2();
60106010

6011+
// Handle std::aligned_storage<...>
6012+
simplifyAlignedStorage();
6013+
60116014
// Mark C++ casts
60126015
markCppCasts();
60136016

@@ -11173,6 +11176,57 @@ void Tokenizer::simplifyNamespaceAliases()
1117311176
}
1117411177
}
1117511178

11179+
void Tokenizer::simplifyAlignedStorage()
11180+
{
11181+
if (!isCPP())
11182+
return;
11183+
11184+
const Standards::cppstd_t std = mSettings.standards.cpp;
11185+
if (std < Standards::CPP11 || std >= Standards::CPP23)
11186+
return;
11187+
11188+
for (Token *tok = list.front(); tok; tok = tok->next()) {
11189+
if (!Token::simpleMatch(tok, "aligned_storage <"))
11190+
continue;
11191+
11192+
tok = tok->next();
11193+
const Token *end = tok->link();
11194+
tok = tok->next();
11195+
11196+
if (!tok)
11197+
break;
11198+
11199+
if (!end)
11200+
continue;
11201+
11202+
for (; tok != end; tok = tok->next()) {
11203+
if (Token::simpleMatch(tok, ",")) {
11204+
tok = tok->next();
11205+
break;
11206+
}
11207+
11208+
if (Token::Match(tok, "(|<"))
11209+
tok = tok->link();
11210+
}
11211+
11212+
std::string str;
11213+
for (; tok != end; tok = tok->next()) {
11214+
str += " " + tok->str();
11215+
}
11216+
11217+
if (str.empty())
11218+
continue;
11219+
11220+
if (!Token::Match(tok, "> :: type %name%"))
11221+
continue;
11222+
11223+
str = str.substr(1);
11224+
11225+
tok = tok->tokAt(3);
11226+
tok->addAttributeAlignas(str);
11227+
}
11228+
}
11229+
1117611230
void Tokenizer::setDirectives(std::list<Directive> directives)
1117711231
{
1117811232
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)