File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -182,14 +182,21 @@ static const std::unordered_set<std::string> stdTypes = { "bool"
182182 , " size_t"
183183 , " void"
184184 , " wchar_t"
185+ , " signed"
186+ , " unsigned"
185187};
186188
189+ bool Token::isStandardType (const std::string& str)
190+ {
191+ return stdTypes.find (str) != stdTypes.end ();
192+ }
193+
187194void Token::update_property_isStandardType ()
188195{
189196 if (mStr .size () < 3 || mStr .size () > 7 )
190197 return ;
191198
192- if (stdTypes. find (mStr )!=stdTypes. end ( )) {
199+ if (isStandardType (mStr )) {
193200 isStandardType (true );
194201 tokType (eType);
195202 }
Original file line number Diff line number Diff line change @@ -1177,6 +1177,8 @@ class CPPCHECKLIB Token {
11771177
11781178 static std::string typeStr (const Token* tok);
11791179
1180+ static bool isStandardType (const std::string& str);
1181+
11801182 /* *
11811183 * @return a pointer to the Enumerator associated with this token.
11821184 */
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ static bool isEnumStart(const Token* tok)
8282 if (!Token::simpleMatch (tok, " {" ))
8383 return false ;
8484 tok = tok->previous ();
85- while (tok && !tok->isKeyword () && Token::Match (tok, " %name%|::|:" ))
85+ while (tok && ( !tok->isKeyword () || Token::isStandardType (tok-> str ()) ) && Token::Match (tok, " %name%|::|:" ))
8686 tok = tok->previous ();
8787 if (Token::simpleMatch (tok, " class" ))
8888 tok = tok->previous ();
Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ class TestSimplifyTypedef : public TestFixture {
222222 TEST_CASE (simplifyTypedef154);
223223 TEST_CASE (simplifyTypedef155);
224224 TEST_CASE (simplifyTypedef156);
225+ TEST_CASE (simplifyTypedef157);
225226
226227 TEST_CASE (simplifyTypedefFunction1);
227228 TEST_CASE (simplifyTypedefFunction2); // ticket #1685
@@ -3758,6 +3759,20 @@ class TestSimplifyTypedef : public TestFixture {
37583759 ASSERT_EQUALS (exp4, tok (code4));
37593760 }
37603761
3762+ void simplifyTypedef157 () {
3763+ const char code[] = " namespace NS1 {\n " // #13451
3764+ " typedef NS2::Bar Bar;\n "
3765+ " using NS2::MyType;\n "
3766+ " }\n "
3767+ " enum E : unsigned int {\n "
3768+ " zero = 0,\n "
3769+ " MyType = 1\n "
3770+ " };\n "
3771+ " namespace NS1 {}\n " ;
3772+ const char exp[] = " enum E : int { zero = 0 , MyType = 1 } ;" ;
3773+ ASSERT_EQUALS (exp, tok (code));
3774+ }
3775+
37613776 void simplifyTypedefFunction1 () {
37623777 {
37633778 const char code[] = " typedef void (*my_func)();\n "
You can’t perform that action at this time.
0 commit comments