File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ struct TokenImpl {
122
122
};
123
123
CppcheckAttributes* mCppcheckAttributes {};
124
124
125
+ // alignas expressions
126
+ std::string mAttributeAlignas ;
127
+
125
128
// For memoization, to speed up parsing of huge arrays #8897
126
129
enum class Cpp11init { UNKNOWN, CPP11INIT, NOINIT } mCpp11init = Cpp11init::UNKNOWN;
127
130
@@ -545,6 +548,19 @@ class CPPCHECKLIB Token {
545
548
void isAttributeMaybeUnused (const bool value) {
546
549
setFlag (fIsAttributeMaybeUnused , value);
547
550
}
551
+ std::string getAttributeAlignas () const {
552
+ return mImpl ->mAttributeAlignas ;
553
+ }
554
+ bool hasAttributeAlignas () const {
555
+ return !mImpl ->mAttributeAlignas .empty ();
556
+ }
557
+ void setAttributeAlignas (const std::string& a) {
558
+ if (a.empty () || mImpl ->mAttributeAlignas .empty ())
559
+ mImpl ->mAttributeAlignas = a;
560
+ else if (a != mImpl ->mAttributeAlignas )
561
+ // mismatching alignas expressions, add both
562
+ mImpl ->mAttributeAlignas += " \n " + a;
563
+ }
548
564
void setCppcheckAttribute (TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) {
549
565
mImpl ->setCppcheckAttribute (type, value);
550
566
}
Original file line number Diff line number Diff line change @@ -6044,6 +6044,8 @@ void Tokenizer::dump(std::ostream &out) const
6044
6044
outs += " isAttributeMaybeUnused=\"true\"";
6045
6045
if (tok->isAttributeUnused())
6046
6046
outs += " isAttributeUnused=\"true\"";
6047
+ if (tok->hasAttributeAlignas())
6048
+ outs += " alignas=\"" + ErrorLogger::toxml(tok->getAttributeAlignas()) + "\"";
6047
6049
if (tok->link()) {
6048
6050
outs += " link=\"";
6049
6051
outs += id_string(tok->link());
@@ -9353,6 +9355,20 @@ void Tokenizer::simplifyCPPAttribute()
9353
9355
}
9354
9356
} else {
9355
9357
if (Token::simpleMatch(tok, "alignas (")) {
9358
+ Token* atok = nullptr;
9359
+ if (Token::Match(tok->previous(), "%name%"))
9360
+ atok = tok->previous();
9361
+ else {
9362
+ while (isCPPAttribute(atok) || isAlignAttribute(atok))
9363
+ atok = skipCPPOrAlignAttribute(atok)->next();
9364
+ }
9365
+ if (atok) {
9366
+ std::string a;
9367
+ for (const Token* t = tok->tokAt(2); t && t->str() != ")"; t = t->next())
9368
+ a += " " + t->str();
9369
+ if (a.size() > 1)
9370
+ atok->setAttributeAlignas(a.substr(1));
9371
+ }
9356
9372
// alignment requirements could be checked here
9357
9373
}
9358
9374
}
You can’t perform that action at this time.
0 commit comments