File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -555,7 +555,7 @@ class CPPCHECKLIB Token {
555555 setFlag (fIsAttributeMaybeUnused , value);
556556 }
557557 std::vector<std::string> getAttributeAlignas () const {
558- return ! mImpl ->mAttributeAlignas ? std::vector<std::string>() : * mImpl -> mAttributeAlignas ;
558+ return mImpl ->mAttributeAlignas ? * mImpl -> mAttributeAlignas : std::vector<std::string>();
559559 }
560560 bool hasAttributeAlignas () const {
561561 return !!mImpl ->mAttributeAlignas ;
Original file line number Diff line number Diff line change @@ -6048,6 +6048,7 @@ void Tokenizer::dump(std::ostream &out) const
60486048 const std::vector<std::string>& a = tok->getAttributeAlignas ();
60496049 outs += " alignas=\" " + ErrorLogger::toxml (a[0 ]) + " \" " ;
60506050 if (a.size () > 1 )
6051+ // we could write all alignas expressions but currently we only need 2
60516052 outs += " alignas2=\" " + ErrorLogger::toxml (a[1 ]) + " \" " ;
60526053 }
60536054 if (tok->link ()) {
Original file line number Diff line number Diff line change @@ -439,6 +439,7 @@ class TestTokenizer : public TestFixture {
439439
440440 TEST_CASE (removeAlignas1);
441441 TEST_CASE (removeAlignas2); // Do not remove alignof in the same way
442+ TEST_CASE (dumpAlignas);
442443
443444 TEST_CASE (simplifyCoroutines);
444445
@@ -7850,6 +7851,17 @@ class TestTokenizer : public TestFixture {
78507851 ASSERT_EQUALS (expected, tokenizeAndStringify (code));
78517852 }
78527853
7854+ void dumpAlignas () {
7855+ Settings settings;
7856+ SimpleTokenizer tokenizer (settings, *this );
7857+ tokenizer.tokenize (" int alignas(8) alignas(16) x;" , false );
7858+ ASSERT (Token::simpleMatch (tokenizer.tokens (), " int x ;" ));
7859+ std::ostringstream ostr;
7860+ tokenizer.dump (ostr);
7861+ const std::string dump = ostr.str ();
7862+ ASSERT (dump.find (" alignas=\" 8\" alignas2=\" 16\" " ) != std::string::npos);
7863+ }
7864+
78537865 void simplifyCoroutines () {
78547866 const Settings settings = settingsBuilder ().cpp (Standards::CPP20 ).build ();
78557867
You can’t perform that action at this time.
0 commit comments