@@ -9223,7 +9223,11 @@ void Tokenizer::simplifyCppcheckAttribute()
9223
9223
9224
9224
void Tokenizer::simplifyCPPAttribute ()
9225
9225
{
9226
- if (!isCPP () || mSettings .standards .cpp < Standards::CPP11)
9226
+ // According to cppreference alignas is a c21 feature however the macro is often available when compiling c11
9227
+ const bool hasAlignas = ((isCPP () && mSettings .standards .cpp >= Standards::CPP11) || (isC () && mSettings .standards .c >= Standards::C11));
9228
+ const bool hasCppAttribute = (isCPP () && mSettings .standards .cpp >= Standards::CPP11);
9229
+
9230
+ if (!hasAlignas && !hasCppAttribute)
9227
9231
return ;
9228
9232
9229
9233
for (Token *tok = list.front (); tok;) {
@@ -9232,6 +9236,10 @@ void Tokenizer::simplifyCPPAttribute()
9232
9236
continue ;
9233
9237
}
9234
9238
if (isCPPAttribute (tok)) {
9239
+ if (!hasCppAttribute) {
9240
+ tok = skipCPPOrAlignAttribute (tok)->next ();
9241
+ continue ;
9242
+ }
9235
9243
if (Token::findsimplematch (tok->tokAt (2 ), " noreturn" , tok->link ())) {
9236
9244
Token * head = skipCPPOrAlignAttribute (tok)->next ();
9237
9245
while (isCPPAttribute (head) || isAlignAttribute (head))
@@ -9283,23 +9291,29 @@ void Tokenizer::simplifyCPPAttribute()
9283
9291
}
9284
9292
}
9285
9293
} else {
9286
- if (Token::simpleMatch (tok, " alignas (" )) {
9287
- Token* atok = nullptr ;
9288
- if (Token::Match (tok->previous (), " %name%" ))
9289
- atok = tok->previous ();
9290
- else {
9291
- atok = tok;
9292
- while (isCPPAttribute (atok) || isAlignAttribute (atok))
9293
- atok = skipCPPOrAlignAttribute (atok)->next ();
9294
- }
9295
- if (atok) {
9296
- std::string a;
9297
- for (const Token* t = tok->tokAt (2 ); t && t->str () != " )" ; t = t->next ())
9298
- a += " " + t->str ();
9299
- if (a.size () > 1 )
9300
- atok->addAttributeAlignas (a.substr (1 ));
9301
- }
9302
- // alignment requirements could be checked here
9294
+ // alignas(expr)
9295
+
9296
+ if (!hasAlignas) {
9297
+ tok = skipCPPOrAlignAttribute (tok)->next ();
9298
+ continue ;
9299
+ }
9300
+
9301
+ // alignment requirements could be checked here
9302
+
9303
+ Token* atok = nullptr ;
9304
+ if (Token::Match (tok->previous (), " %name%" ))
9305
+ atok = tok->previous ();
9306
+ else {
9307
+ atok = tok;
9308
+ while (isCPPAttribute (atok) || isAlignAttribute (atok))
9309
+ atok = skipCPPOrAlignAttribute (atok)->next ();
9310
+ }
9311
+ if (atok) {
9312
+ std::string a;
9313
+ for (const Token* t = tok->tokAt (2 ); t && t->str () != " )" ; t = t->next ())
9314
+ a += " " + t->str ();
9315
+ if (a.size () > 1 )
9316
+ atok->addAttributeAlignas (a.substr (1 ));
9303
9317
}
9304
9318
}
9305
9319
Token::eraseTokens (tok, skipCPPOrAlignAttribute (tok)->next ());
0 commit comments