CheckIncompleteStatement: Fixed false positive generated by CheckIncompleteStatement (bug 2187837)
This commit is contained in:
parent
bacc402d04
commit
30e1d5c06e
|
@ -710,14 +710,14 @@ void CheckIncompleteStatement()
|
|||
if ( parlevel != 0 )
|
||||
continue;
|
||||
|
||||
if ( Match(tok,"; %str%") && !Match(gettok(tok,2), ",") )
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %str%") && !Match(gettok(tok,3), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with string constant";
|
||||
ReportErr(errmsg.str());
|
||||
}
|
||||
|
||||
if ( Match(tok,"; %num%") && !Match(gettok(tok,2), ",") )
|
||||
if ( !Match(tok,"#") && Match(tok->next,"; %num%") && !Match(gettok(tok,3), ",") )
|
||||
{
|
||||
std::ostringstream errmsg;
|
||||
errmsg << FileLine(tok->next) << ": Redundant code: Found a statement that begins with numeric constant";
|
||||
|
|
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
SRCS=CheckBufferOverrun.cpp CheckClass.cpp CheckHeaders.cpp CheckMemoryLeak.cpp CheckOther.cpp CommonCheck.cpp tokenize.cpp
|
||||
OBJS=$(SRCS:%.cpp=%.o)
|
||||
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testmemleak.o testunusedvar.o
|
||||
TESTS=testbufferoverrun.o testcharvar.o testconstructors.o testdivision.o testmemleak.o testother.o testunusedvar.o
|
||||
|
||||
%.o: %.cpp
|
||||
g++ -Wall -pedantic -g -I. -o $@ -c $^
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
// Check for unused variables..
|
||||
|
||||
#include "testsuite.h"
|
||||
#include "tokenize.h"
|
||||
#include "CheckOther.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
|
||||
class TestOther : public TestFixture
|
||||
{
|
||||
public:
|
||||
TestOther() : TestFixture("TestOther")
|
||||
{ }
|
||||
|
||||
private:
|
||||
void check( const char code[] )
|
||||
{
|
||||
// Tokenize..
|
||||
tokens = tokens_back = NULL;
|
||||
std::istringstream istr(code);
|
||||
TokenizeCode( istr );
|
||||
SimplifyTokenList();
|
||||
|
||||
// Clear the error buffer..
|
||||
errout.str("");
|
||||
|
||||
// Check for unused variables..
|
||||
CheckIncompleteStatement();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
TEST_CASE( test1 );
|
||||
TEST_CASE( test2 );
|
||||
}
|
||||
|
||||
void test1()
|
||||
{
|
||||
check( "void foo()\n"
|
||||
"{\n"
|
||||
" const char def[] =\n"
|
||||
"#ifdef ABC\n"
|
||||
" \"abc\";\n"
|
||||
"#else\n"
|
||||
" \"not abc\";\n"
|
||||
"#endif\n"
|
||||
"}\n" );
|
||||
|
||||
ASSERT_EQUALS( std::string(""), errout.str() );
|
||||
}
|
||||
|
||||
void test2()
|
||||
{
|
||||
// Todo: remove the ';' before the string
|
||||
|
||||
check( "void foo()\n"
|
||||
"{\n"
|
||||
" ;\"abc\";\n"
|
||||
"}\n" );
|
||||
|
||||
ASSERT_EQUALS( std::string("[test.cpp:3]: Redundant code: Found a statement that begins with string constant\n"), errout.str() );
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST( TestOther )
|
||||
|
||||
|
Loading…
Reference in New Issue