File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -315,7 +315,9 @@ void CheckType::checkLongCast()
315315 for (const Token *tok = _tokenizer->tokens (); tok; tok = tok->next ()) {
316316 if (!Token::Match (tok, " %var% =" ))
317317 continue ;
318- if (!tok->variable () || !tok->variable ()->isConst () || tok->variable ()->typeStartToken ()->originalName () != " long" )
318+ if (!tok->variable () || !tok->variable ()->isConst () || tok->variable ()->typeStartToken ()->str () != " long" )
319+ continue ;
320+ if (!tok->variable ()->typeStartToken ()->originalName ().empty ())
319321 continue ;
320322 if (Token::Match (tok->next ()->astOperand2 (), " *|<<" ) && astIsIntResult (tok->next ()->astOperand2 ()))
321323 longCastAssignError (tok);
@@ -331,7 +333,7 @@ void CheckType::checkLongCast()
331333 const Token * def = scope->classDef ;
332334 bool islong = false ;
333335 while (Token::Match (def, " %type%|::" )) {
334- if (def->originalName () == " long" ) {
336+ if (def->str () == " long" && def-> originalName (). empty () ) {
335337 islong = true ;
336338 break ;
337339 }
Original file line number Diff line number Diff line change @@ -140,13 +140,21 @@ class TestType : public TestFixture {
140140 void longCastAssign () {
141141 Settings settings;
142142 settings.addEnabled (" style" );
143+ settings.platform (Settings::PlatformType::Unix64);
143144
144145 check (" long f(int x, int y) {\n "
145146 " const long ret = x * y;\n "
146147 " return ret;\n "
147148 " }\n " , &settings);
148149 ASSERT_EQUALS (" [test.cpp:2]: (style) possible loss of information, int result is assigned to long variable\n " , errout.str ());
149150
151+ // typedef
152+ check (" long f(int x, int y) {\n "
153+ " const size_t ret = x * y;\n "
154+ " return ret;\n "
155+ " }\n " , &settings);
156+ ASSERT_EQUALS (" " , errout.str ());
157+
150158 // astIsIntResult
151159 check (" long f(int x, int y) {\n "
152160 " const long ret = (long)x * y;\n "
@@ -163,6 +171,12 @@ class TestType : public TestFixture {
163171 " return x * y;\n "
164172 " }\n " , &settings);
165173 ASSERT_EQUALS (" [test.cpp:2]: (style) possible loss of information, int result is returned as long value\n " , errout.str ());
174+
175+ // typedef
176+ check (" size_t f(int x, int y) {\n "
177+ " return x * y;\n "
178+ " }\n " , &settings);
179+ ASSERT_EQUALS (" " , errout.str ());
166180 }
167181};
168182
You can’t perform that action at this time.
0 commit comments