File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ struct TokenImpl {
122122 };
123123 CppcheckAttributes* mCppcheckAttributes {};
124124
125+ // alignas expressions
126+ std::string mAttributeAlignas ;
127+
125128 // For memoization, to speed up parsing of huge arrays #8897
126129 enum class Cpp11init { UNKNOWN, CPP11INIT, NOINIT } mCpp11init = Cpp11init::UNKNOWN;
127130
@@ -545,6 +548,19 @@ class CPPCHECKLIB Token {
545548 void isAttributeMaybeUnused (const bool value) {
546549 setFlag (fIsAttributeMaybeUnused , value);
547550 }
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+ }
548564 void setCppcheckAttribute (TokenImpl::CppcheckAttributes::Type type, MathLib::bigint value) {
549565 mImpl ->setCppcheckAttribute (type, value);
550566 }
Original file line number Diff line number Diff line change @@ -6044,6 +6044,8 @@ void Tokenizer::dump(std::ostream &out) const
60446044 outs += " isAttributeMaybeUnused=\" true\" " ;
60456045 if (tok->isAttributeUnused ())
60466046 outs += " isAttributeUnused=\" true\" " ;
6047+ if (tok->hasAttributeAlignas ())
6048+ outs += " alignas=\" " + ErrorLogger::toxml (tok->getAttributeAlignas ()) + " \" " ;
60476049 if (tok->link ()) {
60486050 outs += " link=\" " ;
60496051 outs += id_string (tok->link ());
@@ -9353,6 +9355,20 @@ void Tokenizer::simplifyCPPAttribute()
93539355 }
93549356 } else {
93559357 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+ }
93569372 // alignment requirements could be checked here
93579373 }
93589374 }
You can’t perform that action at this time.
0 commit comments