diff --git a/test/.clang-tidy b/test/.clang-tidy new file mode 100644 index 00000000000..1f832f2d39e --- /dev/null +++ b/test/.clang-tidy @@ -0,0 +1,7 @@ +--- +InheritParentConfig: true +CheckOptions: + #- key: bugprone-unused-return-value.CheckedFunctions + # value: '::.*' + - key: bugprone-unused-return-value.AllowCastToVoid + value: 'true' \ No newline at end of file diff --git a/test/fixture.cpp b/test/fixture.cpp index a13ccf2c803..032056c9635 100644 --- a/test/fixture.cpp +++ b/test/fixture.cpp @@ -216,9 +216,9 @@ std::string TestFixture::deleteLineNumber(const std::string &message) return result; } -void TestFixture::assertEqualsWithoutLineNumbers(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const +bool TestFixture::assertEqualsWithoutLineNumbers(const char * const filename, const unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg) const { - assertEquals(filename, linenr, deleteLineNumber(expected), deleteLineNumber(actual), msg); + return assertEquals(filename, linenr, deleteLineNumber(expected), deleteLineNumber(actual), msg); } bool TestFixture::assertEquals(const char * const filename, const unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg) const @@ -237,20 +237,21 @@ bool TestFixture::assertEquals(const char * const filename, const unsigned int l bool TestFixture::assertEquals(const char * const filename, const unsigned int linenr, const long long expected, const long long actual, const std::string &msg) const { if (expected != actual) { - assertEquals(filename, linenr, std::to_string(expected), std::to_string(actual), msg); + return assertEquals(filename, linenr, std::to_string(expected), std::to_string(actual), msg); } - return expected == actual; + return true; } -void TestFixture::assertEqualsDouble(const char * const filename, const unsigned int linenr, const double expected, const double actual, const double tolerance, const std::string &msg) const +bool TestFixture::assertEqualsDouble(const char * const filename, const unsigned int linenr, const double expected, const double actual, const double tolerance, const std::string &msg) const { if (expected < (actual - tolerance) || expected > (actual + tolerance)) { std::ostringstream ostr1; ostr1 << expected; std::ostringstream ostr2; ostr2 << actual; - assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg); + return assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg); } + return false; } void TestFixture::todoAssertEquals(const char * const filename, const unsigned int linenr, @@ -264,7 +265,7 @@ void TestFixture::todoAssertEquals(const char * const filename, const unsigned i ++succeeded_todos_counter; } else { - assertEquals(filename, linenr, current, actual); + (void)assertEquals(filename, linenr, current, actual); ++todos_counter; } } diff --git a/test/fixture.h b/test/fixture.h index 313a2b5157e..c26d20ef696 100644 --- a/test/fixture.h +++ b/test/fixture.h @@ -95,12 +95,12 @@ class TestFixture : public ErrorLogger { void assertEqualsFailed(const char* filename, unsigned int linenr, const std::string& expected, const std::string& actual, const std::string& msg) const; bool assertEquals(const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const; - void assertEqualsWithoutLineNumbers(const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const; + bool assertEqualsWithoutLineNumbers(const char * filename, unsigned int linenr, const std::string &expected, const std::string &actual, const std::string &msg = emptyString) const; bool assertEquals(const char * filename, unsigned int linenr, const char expected[], const std::string& actual, const std::string &msg = emptyString) const; bool assertEquals(const char * filename, unsigned int linenr, const char expected[], const char actual[], const std::string &msg = emptyString) const; bool assertEquals(const char * filename, unsigned int linenr, const std::string& expected, const char actual[], const std::string &msg = emptyString) const; bool assertEquals(const char * filename, unsigned int linenr, long long expected, long long actual, const std::string &msg = emptyString) const; - void assertEqualsDouble(const char * filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg = emptyString) const; + bool assertEqualsDouble(const char * filename, unsigned int linenr, double expected, double actual, double tolerance, const std::string &msg = emptyString) const; void todoAssertEquals(const char * filename, unsigned int linenr, const std::string &wanted, const std::string ¤t, const std::string &actual) const; @@ -296,30 +296,30 @@ class TestInstance { }; // TODO: most asserts do not actually assert i.e. do not return -#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); try { NAME(); teardownTest(); } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } } while (false) -#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return -#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) assert_(FILE_, LINE_, (CONDITION)) -#define CHECK_EQUALS( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL)) +#define TEST_CASE( NAME ) do { if (prepareTest(#NAME)) { setVerbose(false); try { NAME(); teardownTest(); } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } } while (false) +#define ASSERT( CONDITION ) if (!assert_(__FILE__, __LINE__, (CONDITION))) return +#define ASSERT_LOC( CONDITION, FILE_, LINE_ ) (void)assert_(FILE_, LINE_, (CONDITION)) +#define CHECK_EQUALS( EXPECTED, ACTUAL ) (void)assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL)) // *INDENT-OFF* #define ASSERT_EQUALS( EXPECTED, ACTUAL ) do { try { if (!assertEquals(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false) // *INDENT-ON* -#define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL) -#define ASSERT_EQUALS_DOUBLE( EXPECTED, ACTUAL, TOLERANCE ) assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE) -#define ASSERT_EQUALS_LOC_MSG( EXPECTED, ACTUAL, MSG, FILE_, LINE_ ) assertEquals(FILE_, LINE_, EXPECTED, ACTUAL, MSG) -#define ASSERT_EQUALS_MSG( EXPECTED, ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG) -#define ASSERT_EQUALS_ENUM( EXPECTED, ACTUAL ) if (!assertEqualsEnum(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return -#define ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_THROW_EQUALS_2( CMD, EXCEPTION, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_THROW_INTERNAL_EQUALS( CMD, TYPE, EXPECTED ) do { try { CMD; assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) -#define ASSERT_NO_THROW( CMD ) do { try { CMD; } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false) -#define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { CMD; } catch (const EXCEPTION&) {} catch (...) { assertThrow(__FILE__, __LINE__); } } while (false) +#define ASSERT_EQUALS_WITHOUT_LINENUMBERS( EXPECTED, ACTUAL ) (void)assertEqualsWithoutLineNumbers(__FILE__, __LINE__, EXPECTED, ACTUAL) +#define ASSERT_EQUALS_DOUBLE( EXPECTED, ACTUAL, TOLERANCE ) (void)assertEqualsDouble(__FILE__, __LINE__, EXPECTED, ACTUAL, TOLERANCE) +#define ASSERT_EQUALS_LOC_MSG( EXPECTED, ACTUAL, MSG, FILE_, LINE_ ) (void)assertEquals(FILE_, LINE_, EXPECTED, ACTUAL, MSG) +#define ASSERT_EQUALS_MSG( EXPECTED, ACTUAL, MSG ) (void)assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG) +#define ASSERT_EQUALS_ENUM( EXPECTED, ACTUAL ) if (!assertEqualsEnum(__FILE__, __LINE__, (EXPECTED), (ACTUAL))) return +#define ASSERT_THROW( CMD, EXCEPTION ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&) {} catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_EQUALS( CMD, EXCEPTION, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { (void)assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_EQUALS_2( CMD, EXCEPTION, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const EXCEPTION&e) { (void)assertEquals(__FILE__, __LINE__, EXPECTED, e.what()); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_INTERNAL( CMD, TYPE ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { (void)assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_THROW_INTERNAL_EQUALS( CMD, TYPE, EXPECTED ) do { try { (void)(CMD); assertThrowFail(__FILE__, __LINE__); } catch (const InternalError& e) { (void)assertEqualsEnum(__FILE__, __LINE__, InternalError::TYPE, e.type); (void)assertEquals(__FILE__, __LINE__, EXPECTED, e.errorMessage); } catch (...) { assertThrowFail(__FILE__, __LINE__); } } while (false) +#define ASSERT_NO_THROW( CMD ) do { try { (void)(CMD); } catch (...) { assertNoThrowFail(__FILE__, __LINE__); } } while (false) +#define TODO_ASSERT_THROW( CMD, EXCEPTION ) do { try { (void)(CMD); } catch (const EXCEPTION&) {} catch (...) { assertThrow(__FILE__, __LINE__); } } while (false) #define TODO_ASSERT( CONDITION ) do { const bool condition=(CONDITION); todoAssertEquals(__FILE__, __LINE__, true, false, condition); } while (false) #define TODO_ASSERT_EQUALS( WANTED, CURRENT, ACTUAL ) todoAssertEquals(__FILE__, __LINE__, WANTED, CURRENT, ACTUAL) -#define EXPECT_EQ( EXPECTED, ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) +#define EXPECT_EQ( EXPECTED, ACTUAL ) (void)assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL) #define REGISTER_TEST( CLASSNAME ) namespace { class CLASSNAME ## Instance : public TestInstance { public: CLASSNAME ## Instance() : TestInstance(#CLASSNAME) {} TestFixture* create() override { impl.reset(new CLASSNAME); return impl.get(); } }; CLASSNAME ## Instance instance_ ## CLASSNAME; } -#define PLATFORM( P, T ) do { std::string errstr; assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {exename}), errstr); } while (false) +#define PLATFORM( P, T ) do { std::string errstr; (void)assertEquals(__FILE__, __LINE__, true, P.set(Platform::toString(T), errstr, {exename}), errstr); } while (false) #endif // fixtureH diff --git a/test/testastutils.cpp b/test/testastutils.cpp index f7a55c9c2b6..d1e6d18fdf8 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -231,10 +231,10 @@ class TestAstUtils : public TestFixture { void isVariableChangedTest() { // #8211 - no lhs for >> , do not crash - isVariableChanged("void f() {\n" - " int b;\n" - " if (b) { (int)((INTOF(8))result >> b); }\n" - "}", "if", "}"); + (void)isVariableChanged("void f() {\n" + " int b;\n" + " if (b) { (int)((INTOF(8))result >> b); }\n" + "}", "if", "}"); // #9235 ASSERT_EQUALS(false, isVariableChanged("void f() {\n" diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 9a70e62cded..b743b6a81bd 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -5204,7 +5204,7 @@ class TestBufferOverrun : public TestFixture { std::list fileInfo; Check& c = getCheck(); fileInfo.push_back(c.getFileInfo(tokenizer, settings0)); - c.analyseWholeProgram(ctu, fileInfo, settings0, *this); + c.analyseWholeProgram(ctu, fileInfo, settings0, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 00810de9dd1..7909eb923c5 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -1363,7 +1363,7 @@ class TestClangImport : public TestFixture { "`-CXXConstructorDecl 0x5603791b5600 parent 0x560379197110 prev 0x5603791974b8 col:47 b 'void (A &)'\n" " |-ParmVarDecl 0x5603791b5570 col:52 'A &'\n" " `-CompoundStmt 0x5603791b5700 \n"; - parse(clang); // don't crash + (void)parse(clang); // don't crash } }; diff --git a/test/testclass.cpp b/test/testclass.cpp index f440381c317..130e4926d5d 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8933,7 +8933,7 @@ class TestClass : public TestFixture { } // Check code.. - check.analyseWholeProgram(nullptr, fileInfo, settingsDefault, *this); + check.analyseWholeProgram(nullptr, fileInfo, settingsDefault, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 103e9fa8dcd..652388d917a 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -278,7 +278,7 @@ class TestGarbage : public TestFixture { // run alternate check first. It should only ensure stability - so we catch exceptions here. try { - checkCodeInternal(code, !cpp); + (void)checkCodeInternal(code, !cpp); } catch (const InternalError&) {} return checkCodeInternal(code, cpp); @@ -435,7 +435,7 @@ class TestGarbage : public TestFixture { } void garbageCode1() { - checkCode("struct x foo_t; foo_t typedef y;"); + (void)checkCode("struct x foo_t; foo_t typedef y;"); } void garbageCode2() { //#4300 (segmentation fault) @@ -450,7 +450,7 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), SYNTAX); } - void garbageCode5() { // #5168 + void garbageCode5() { // #5168 (segmentation fault) ASSERT_THROW_INTERNAL(checkCode("( asm : ; void : );"), SYNTAX); } @@ -485,20 +485,20 @@ class TestGarbage : public TestFixture { } void garbageCode12() { // do not crash - checkCode("{ g; S (void) { struct } { } int &g; }"); + (void)checkCode("{ g; S (void) { struct } { } int &g; }"); ignore_errout(); // we do not care about the output } - void garbageCode13() { - checkCode("struct C {} {} x"); + void garbageCode13() { // Ticket #2607 - crash + (void)checkCode("struct C {} {} x"); } void garbageCode15() { // Ticket #5203 ASSERT_THROW_INTERNAL(checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }"), SYNTAX); } - void garbageCode16() { - checkCode("{ } A() { delete }"); // #6080 + void garbageCode16() { // #6080 (segmentation fault) + (void)checkCode("{ } A() { delete }"); // #6080 ignore_errout(); // we do not care about the output } @@ -585,20 +585,20 @@ class TestGarbage : public TestFixture { "}"), SYNTAX); } - void garbageCode28() { + void garbageCode28() { // #5702 (segmentation fault) // 5702 - checkCode("struct R1 {\n" - " int a;\n" - " R1 () : a { }\n" - "};"); + (void)checkCode("struct R1 {\n" + " int a;\n" + " R1 () : a { }\n" + "};"); ignore_errout(); // we do not care about the output } void garbageCode30() { // simply survive - a syntax error would be even better (#5867) - checkCode("void f(int x) {\n" - " x = 42\n" - "}"); + (void)checkCode("void f(int x) {\n" + " x = 42\n" + "}"); ignore_errout(); // we do not care about the output } @@ -606,8 +606,8 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("typedef struct{}x[([],)]typedef e y;(y,x 0){}"), SYNTAX); } - void garbageCode33() { // #6613 - checkCode("main(()B{});"); + void garbageCode33() { // #6613 (segmentation fault) + (void)checkCode("main(()B{});"); } // Bug #6626 crash: Token::astOperand2() const ( do while ) @@ -635,30 +635,30 @@ class TestGarbage : public TestFixture { void garbageCode37() { // #5166 segmentation fault (invalid code) in lib/checkother.cpp:329 ( void * f { } void b ( ) { * f } ) - checkCode("void * f { } void b ( ) { * f }"); + (void)checkCode("void * f { } void b ( ) { * f }"); ignore_errout(); // we do not care about the output } - void garbageCode38() { // Ticket #6666 - checkCode("{ f2 { } } void f3 () { delete[] } { }"); + void garbageCode38() { // Ticket #6666 (segmentation fault) + (void)checkCode("{ f2 { } } void f3 () { delete[] } { }"); ignore_errout(); // we do not care about the output } - void garbageCode40() { // #6620 - checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"); + void garbageCode40() { // #6620 (segmentation fault) + (void)checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }"); // test doesn't seem to work on any platform: ASSERT_THROW(checkCode("{ ( ) () { virtual } ; { } E } A { : { } ( ) } * const ( ) const { }", "test.c"), InternalError); } - void garbageCode41() { // #6685 - checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }"); + void garbageCode41() { // #6685 (segmentation fault) + (void)checkCode(" { } { return } *malloc(__SIZE_TYPE__ size); *memcpy(void n); static * const () { memcpy (*slot, 3); } { (); } { }"); } - void garbageCode42() { // #5760 - checkCode("{ } * const ( ) { }"); + void garbageCode42() { // #5760 (segmentation fault) + (void)checkCode("{ } * const ( ) { }"); } - void garbageCode43() { // #6703 - checkCode("int { }; struct A a = { }"); + void garbageCode43() { // #6703 (segmentation fault) + (void)checkCode("int { }; struct A a = { }"); } void garbageCode44() { // #6704 @@ -669,17 +669,17 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("struct true template < > { = } > struct Types \"s\" ; static_assert < int > ;"), SYNTAX); } - void garbageCode46() { // #6705 - checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }"); + void garbageCode46() { // #6705 (segmentation fault) + (void)checkCode(" { bar(char *x); void foo (int ...) { struct } va_list ap; va_start(ap, size); va_arg(ap, (d)); }"); ignore_errout(); // we do not care about the output } - void garbageCode47() { // #6706 - checkCode(" { { }; }; * new private: B: B;"); + void garbageCode47() { // #6706 (segmentation fault) + (void)checkCode(" { { }; }; * new private: B: B;"); } - void garbageCode48() { // #6712 - checkCode(" { d\" ) d ...\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }"); + void garbageCode48() { // #6712 (segmentation fault) + (void)checkCode(" { d\" ) d ...\" } int main ( ) { ( ) catch ( A a ) { { } catch ( ) \"\" } }"); ignore_errout(); // we do not care about the output } @@ -736,17 +736,17 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("{ } foo(void (*bar)(void))"), SYNTAX); } - void garbageCode65() { // #6741 + void garbageCode65() { // #6741 (segmentation fault) // TODO write some syntax error - checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref"); + (void)checkCode("{ } { } typedef int u_array[]; typedef u_array &u_array_ref; (u_array_ref arg) { } u_array_ref"); } void garbageCode66() { // #6742 ASSERT_THROW_INTERNAL(checkCode("{ { } }; { { } }; { }; class bar : public virtual"), SYNTAX); } - void garbageCode68() { // #6745 - checkCode("(int a[3]); typedef void (*fp) (void); fp"); + void garbageCode68() { // #6745 (segmentation fault) + (void)checkCode("(int a[3]); typedef void (*fp) (void); fp"); } void garbageCode69() { // #6746 @@ -810,8 +810,8 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("int main ( [ ] ) { " " [ ] ; int i = 0 ; do { } ; } ( [ ] ) { }"), SYNTAX); // do not crash } - void garbageCode85() { // #6784 - checkCode("{ } { } typedef void ( *VoidFunc() ) ( ) ; VoidFunc"); // do not crash + void garbageCode85() { // #6784 (segmentation fault) + (void)checkCode("{ } { } typedef void ( *VoidFunc() ) ( ) ; VoidFunc"); // do not crash } void garbageCode86() { // #6785 @@ -879,8 +879,8 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("template < class =( , ) X = 1> struct A {}; A a;"), SYNTAX); } - void garbageCode102() { // #6846 - checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"); + void garbageCode102() { // #6846 (segmentation fault) + (void)checkCode("struct Object { ( ) ; Object & operator= ( Object ) { ( ) { } if ( this != & b ) } }"); ignore_errout(); // we do not care about the output } @@ -909,7 +909,7 @@ class TestGarbage : public TestFixture { } void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks" - checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }"); + (void)checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }"); } void garbageCode110() { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str" @@ -925,10 +925,10 @@ class TestGarbage : public TestFixture { } void garbageCode114() { // #2118 - checkCode("Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n" - " for (unsigned i = 0 ; i < count; i++) {\n" - " }\n" - "});"); + ASSERT_NO_THROW(checkCode("Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n" + " for (unsigned i = 0 ; i < count; i++) {\n" + " }\n" + "});")); } void garbageCode115() { // #5506 @@ -954,15 +954,15 @@ class TestGarbage : public TestFixture { "}"), SYNTAX); } - void garbageCode119() { // #5598 - checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); + void garbageCode119() { // #5598 (segmentation fault) + (void)checkCode("{ { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); ignore_errout(); // we do not care about the output } - void garbageCode120() { // #4927 - checkCode("int main() {\n" - " return 0\n" - "}"); + void garbageCode120() { // #4927 (segmentation fault) + (void)checkCode("int main() {\n" + " return 0\n" + "}"); ASSERT_EQUALS("", errout_str()); } @@ -972,20 +972,20 @@ class TestGarbage : public TestFixture { "+?" "?="), SYNTAX); } - void garbageCode122() { // #6303 - checkCode("void foo() {\n" - "char *a = malloc(10);\n" - "a[0]\n" - "}"); + void garbageCode122() { // #6303 (segmentation fault) + (void)checkCode("void foo() {\n" + "char *a = malloc(10);\n" + "a[0]\n" + "}"); ignore_errout(); // we do not care about the output } void garbageCode123() { - checkCode("namespace pr16989 {\n" - " class C {\n" - " C tpl_mem(T *) { return }\n" - " };\n" - "}"); + (void)checkCode("namespace pr16989 {\n" + " class C {\n" + " C tpl_mem(T *) { return }\n" + " };\n" + "}"); ignore_errout(); // we do not care about the output } @@ -1000,16 +1000,16 @@ class TestGarbage : public TestFixture { SYNTAX); } - void garbageCode127() { // #6667 - checkCode("extern \"C\" int printf(const char* fmt, ...);\n" - "class A {\n" - "public:\n" - " int Var;\n" - " A(int arg) { Var = arg; }\n" - " ~A() { printf(\"A d'tor\\n\"); }\n" - "};\n" - " const A& foo(const A& arg) { return arg; }\n" - " foo(A(12)).Var"); + void garbageCode127() { // #6667 (segmentation fault) + (void)checkCode("extern \"C\" int printf(const char* fmt, ...);\n" + "class A {\n" + "public:\n" + " int Var;\n" + " A(int arg) { Var = arg; }\n" + " ~A() { printf(\"A d'tor\\n\"); }\n" + "};\n" + " const A& foo(const A& arg) { return arg; }\n" + " foo(A(12)).Var"); ignore_errout(); // we do not care about the output } @@ -1095,37 +1095,37 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("() template < T = typename = x > struct a {} { f () }"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("template < T = typename = > struct a { f }"), SYNTAX); - checkCode("struct S { int i, j; }; " - "template struct X {}; " - "X<&S::i, int> x = X<&S::i, int>(); " - "X<&S::j, int> y = X<&S::j, int>();"); + (void)checkCode("struct S { int i, j; }; " + "template struct X {}; " + "X<&S::i, int> x = X<&S::i, int>(); " + "X<&S::j, int> y = X<&S::j, int>();"); ignore_errout(); // we are not interested in the output - checkCode("template struct A {}; " - "template <> struct A {}; " - "void foo(const void* f = 0) {}"); - checkCode("template struct A { " - " static const int s = 0; " - "}; " - "A a;"); - checkCode("template class A {}; " - "template > class B {}; " - "template > class C { " - " C() : _a(0), _b(0) {} " - " int _a, _b; " - "};"); - checkCode("template struct A { " - " static int i; " - "}; " - "void f() { A::i = 0; }"); + (void)checkCode("template struct A {}; " + "template <> struct A {}; " + "void foo(const void* f = 0) {}"); + (void)checkCode("template struct A { " + " static const int s = 0; " + "}; " + "A a;"); + (void)checkCode("template class A {}; " + "template > class B {}; " + "template > class C { " + " C() : _a(0), _b(0) {} " + " int _a, _b; " + "};"); + (void)checkCode("template struct A { " + " static int i; " + "}; " + "void f() { A::i = 0; }"); ignore_errout(); // we are not interested in the output } - void garbageCode135() { // #4994 - checkCode("long f () {\n" - " return a >> extern\n" - "}\n" - "long a = 1 ;\n" - "long b = 2 ;"); + void garbageCode135() { // #4994 (segmentation fault) + (void)checkCode("long f () {\n" + " return a >> extern\n" + "}\n" + "long a = 1 ;\n" + "long b = 2 ;"); ignore_errout(); // we are not interested in the output } @@ -1138,16 +1138,16 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("\" \" typedef signed char f; \" \"; void a() { f * s = () &[]; (; ) (; ) }"), SYNTAX); } - void garbageCode138() { // #6660 - checkCode("CS_PLUGIN_NAMESPACE_BEGIN(csparser)\n" - "{\n" - " struct foo\n" - " {\n" - " union\n" - " {};\n" - " } halo;\n" - "}\n" - "CS_PLUGIN_NAMESPACE_END(csparser)"); + void garbageCode138() { // #6660 (segmentation fault) + (void)checkCode("CS_PLUGIN_NAMESPACE_BEGIN(csparser)\n" + "{\n" + " struct foo\n" + " {\n" + " union\n" + " {};\n" + " } halo;\n" + "}\n" + "CS_PLUGIN_NAMESPACE_END(csparser)"); ignore_errout(); // we are not interested in the output } @@ -1220,11 +1220,11 @@ class TestGarbage : public TestFixture { "b[0][0]"), UNKNOWN_MACRO); } - void garbageCode149() { // #7085 - checkCode("int main() {\n" - " for (j = 0; j < 1; j)\n" - " j6;\n" - "}"); + void garbageCode149() { // #7085 (segmentation fault) + (void)checkCode("int main() {\n" + " for (j = 0; j < 1; j)\n" + " j6;\n" + "}"); ignore_errout(); // we do not care about the output } @@ -1238,17 +1238,17 @@ class TestGarbage : public TestFixture { } void garbageCode151() { // #4911 - bad simplification => don't crash - checkCode("void f() {\n" - " int a;\n" - " do { a=do_something() } while (a);\n" - "}"); + (void)checkCode("void f() {\n" + " int a;\n" + " do { a=do_something() } while (a);\n" + "}"); } - void garbageCode152() { // happened in travis, originally from llvm clang code + void garbageCode152() { // happened in travis, originally from llvm clang code (segmentation fault) const char code[] = "template \n" "static std::string foo(char *Bla) {\n" " while (Bla[1] && Bla[1] != ',') }\n"; - checkCode(code); + (void)checkCode(code); ignore_errout(); // we are not interested in the output } @@ -1256,8 +1256,8 @@ class TestGarbage : public TestFixture { TODO_ASSERT_THROW(checkCode("enum { X = << { X } } { X X } enum { X = << { ( X ) } } { } X */"), InternalError); } - void garbageCode154() { - checkCode("\"abc\"[];"); + void garbageCode154() { // #7112 (segmentation fault) + (void)checkCode("\"abc\"[];"); } void garbageCode156() { // #7120 @@ -1272,8 +1272,8 @@ class TestGarbage : public TestFixture { "template std::swap\n"), SYNTAX); } - void garbageCode158() { // #3238 - checkCode("__FBSDID(\"...\");"); + void garbageCode158() { // #3238 (segmentation fault) + (void)checkCode("__FBSDID(\"...\");"); } void garbageCode159() { // #7119 @@ -1314,17 +1314,18 @@ class TestGarbage : public TestFixture { } void garbageSymbolDatabase() { - checkCode("void f( { u = 1 ; } ) { }"); + (void)checkCode("void f( { u = 1 ; } ) { }"); ASSERT_THROW_INTERNAL(checkCode("{ }; void namespace A::f; { g() { int } }"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("class Foo {}; class Bar : public Foo"), SYNTAX); - checkCode("YY_DECL { switch (yy_act) {\n" - " case 65: YY_BREAK\n" - " case YY_STATE_EOF(block):\n" - " yyterminate();\n" - "} }"); // #5663 + // #5663 (segmentation fault) + (void)checkCode("YY_DECL { switch (yy_act) {\n" + " case 65: YY_BREAK\n" + " case YY_STATE_EOF(block):\n" + " yyterminate();\n" + "} }"); ignore_errout(); // we are not interested in the output } @@ -1333,7 +1334,7 @@ class TestGarbage : public TestFixture { "int #define for (i = avx_test i < c[i]; i++)\n" "b[i + 3] = a[i] * {}"), SYNTAX); // Don't hang (#5787) - checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) + (void)checkCode("START_SECTION([EXTRA](bool isValid(const String &filename)))"); // Don't crash (#5991) // #8352 ASSERT_THROW_INTERNAL(checkCode("else return % name5 name2 - =name1 return enum | { - name3 1 enum != >= 1 >= ++ { { || " @@ -1343,7 +1344,7 @@ class TestGarbage : public TestFixture { } void templateSimplifierCrashes() { - checkCode( // #5950 + (void)checkCode( // #5950 (segmentation fault) "struct A {\n" " template operator T*();\n" "};\n" @@ -1365,21 +1366,21 @@ class TestGarbage : public TestFixture { " }\n" "}"); - checkCode( // #6034 - "template class T, typename... Args>\n" - "struct foo > {\n" - " const bool value = true;\n" - "};\n" - "\n" - "template\n" - "struct int_\n" - "{};\n" - "\n" - "int main() {\n" - " foo >::value;\n" - "}"); + ASSERT_NO_THROW(checkCode( // #6034 + "template class T, typename... Args>\n" + "struct foo > {\n" + " const bool value = true;\n" + "};\n" + "\n" + "template\n" + "struct int_\n" + "{};\n" + "\n" + "int main() {\n" + " foo >::value;\n" + "}")); - checkCode( // #6117 + (void)checkCode( // #6117 (segmentation fault) "template struct something_like_tuple\n" "{};\n" "template struct is_last {\n" @@ -1398,7 +1399,7 @@ class TestGarbage : public TestFixture { "SA ((is_last::value == false));"); ignore_errout(); // we are not interested in the output - checkCode( // #6225 + (void)checkCode( // #6225 (use-after-free) "template \n" "void templ_fun_with_ty_pack() {}\n" "\n" @@ -1447,8 +1448,8 @@ class TestGarbage : public TestFixture { } void garbageCode168() { - // 7246 - checkCode("long foo(void) { return *bar; }", false); + // #7246 (segmentation fault) + (void)checkCode("long foo(void) { return *bar; }", false); ignore_errout(); // we do not care about the output } @@ -1491,8 +1492,8 @@ class TestGarbage : public TestFixture { "}"), SYNTAX); } - void garbageCode176() { // #7527 - checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;"); + void garbageCode176() { // #7257 (segmentation fault) + (void)checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;"); ignore_errout(); // we are not interested in the output } @@ -1517,7 +1518,7 @@ class TestGarbage : public TestFixture { } void garbageCode185() { // #6011 crash in libreoffice failure to create proper AST - checkCode( + (void)checkCode( "namespace binfilter\n" "{\n" " BOOL EnhWMFReader::ReadEnhWMF()\n" @@ -1538,16 +1539,16 @@ class TestGarbage : public TestFixture { const char inp[] = "0|\0|0>;\n"; ASSERT_THROW_INTERNAL(checkCode(inp), SYNTAX); - checkCode("template struct S : A< B || C > {};"); // No syntax error: #8390 - checkCode("static_assert(A || B, ab);"); + (void)checkCode("template struct S : A< B || C > {};"); // No syntax error: #8390 + (void)checkCode("static_assert(A || B, ab);"); } void garbageCode188() { // #8255 ASSERT_THROW_INTERNAL(checkCode("{z r(){(){for(;<(x);){if(0==0)}}}}"), SYNTAX); } - void garbageCode189() { // #8317 - checkCode("t&n(){()()[](){()}}$"); + void garbageCode189() { // #8317 (segmentation fault) + (void)checkCode("t&n(){()()[](){()}}$"); } void garbageCode190() { // #8307 @@ -1565,7 +1566,7 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("struct A { int f(struct); };"), SYNTAX); // The following code is valid and should not trigger any error - checkCode("struct A { int f ( char ) ; } ;"); + ASSERT_NO_THROW(checkCode("struct A { int f ( char ) ; } ;")); } void garbageCode192() { // #8386 (segmentation fault) @@ -1582,14 +1583,14 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("{((()))(return 1||);}"), SYNTAX); } - // #8709 - no garbage but to avoid stability regression + // #8709 - no garbage but to avoid stability regression (segmentation fault) void garbageCode195() { - checkCode("a b;\n" - "void c() {\n" - " switch (d) { case b:; }\n" - " double e(b);\n" - " if(e <= 0) {}\n" - "}"); + (void)checkCode("a b;\n" + "void c() {\n" + " switch (d) { case b:; }\n" + " double e(b);\n" + " if(e <= 0) {}\n" + "}"); ignore_errout(); // we do not care about the output } @@ -1614,7 +1615,7 @@ class TestGarbage : public TestFixture { "}"), SYNTAX); } - // #8752 + // #8752 (segmentation fault) void garbageCode199() { ASSERT_THROW_INTERNAL(checkCode("d f(){e n00e0[]n00e0&" "0+f=0}"), SYNTAX); } @@ -1636,9 +1637,9 @@ class TestGarbage : public TestFixture { ignore_errout(); } - void garbageCode203() { // #8972 + void garbageCode203() { // #8972 (segmentation fault) ASSERT_THROW_INTERNAL(checkCode("{ > () {} }"), SYNTAX); - checkCode("template <> a > ::b();"); + (void)checkCode("template <> a > ::b();"); } void garbageCode204() { @@ -1698,18 +1699,18 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("{\"\"[(1||)];}"), SYNTAX); } - void garbageCode214() { - checkCode("THIS FILE CONTAINS VARIOUS TEXT"); + void garbageCode214() { // segmentation fault + (void)checkCode("THIS FILE CONTAINS VARIOUS TEXT"); } void garbageCode215() { // daca@home script with extension .c ASSERT_THROW_INTERNAL(checkCode("a = [1,2,3];"), SYNTAX); } - void garbageCode216() { // #7884 - checkCode("template struct A {};\n" - "template struct A {}; \n" - "A a;"); + void garbageCode216() { // #7884 (out-of-memory) + (void)checkCode("template struct A {};\n" + "template struct A {}; \n" + "A a;"); } void garbageCode217() { // #10011 @@ -1724,11 +1725,11 @@ class TestGarbage : public TestFixture { ASSERT_THROW_INTERNAL(checkCode("d f(){t n0000 const[]n0000+0!=n0000,(0)}"), SYNTAX); } void garbageCode219() { // #10101 - checkCode("typedef void (*func) (addr) ;\n" - "void bar(void) {\n" - " func f;\n" - " f & = (func)42;\n" - "}\n"); // don't crash + (void)checkCode("typedef void (*func) (addr) ;\n" + "void bar(void) {\n" + " func f;\n" + " f & = (func)42;\n" + "}\n"); // don't crash ignore_errout(); // we are not interested in the output } void garbageCode220() { // #6832 @@ -1826,7 +1827,7 @@ class TestGarbage : public TestFixture { void syntaxErrorFuzzerCliType1() { ASSERT_THROW_INTERNAL(checkCode("void f(){x=0,return return''[]()}"), SYNTAX); ASSERT_THROW_INTERNAL(checkCode("void f(){x='0'++'0'(return)[];}"), SYNTAX); // #9063 - checkCode("void f(){*(int *)42=0;}"); // no syntax error + (void)checkCode("void f(){*(int *)42=0;}"); // no syntax error ignore_errout(); // we are not interested in the output ASSERT_THROW_INTERNAL(checkCode("void f() { x= 'x' > typedef name5 | ( , ;){ } (); }"), SYNTAX); // #9067 ASSERT_THROW_INTERNAL(checkCode("void f() { x= {}( ) ( 'x')[ ] (); }"), SYNTAX); // #9068 @@ -1850,30 +1851,30 @@ class TestGarbage : public TestFixture { } void nonGarbageCode1() { - checkCode("template class List {\n" - "public:\n" - " List();\n" - " virtual ~List();\n" - " template< class Predicate > u_int DeleteIf( const Predicate &pred );\n" - "};\n" - "template< class T >\n" - "template< class Predicate > int\n" - "List::DeleteIf( const Predicate &pred )\n" - "{}"); + ASSERT_NO_THROW(checkCode("template class List {\n" + "public:\n" + " List();\n" + " virtual ~List();\n" + " template< class Predicate > u_int DeleteIf( const Predicate &pred );\n" + "};\n" + "template< class T >\n" + "template< class Predicate > int\n" + "List::DeleteIf( const Predicate &pred )\n" + "{}")); ignore_errout(); // we are not interested in the output // #8749 - checkCode( - "struct A {\n" - " void operator+=(A&) && = delete;\n" - "};"); + ASSERT_NO_THROW(checkCode( + "struct A {\n" + " void operator+=(A&) && = delete;\n" + "};")); // #8788 - checkCode( - "struct foo;\n" - "void f() {\n" - " auto fn = []() -> foo* { return new foo(); };\n" - "}"); + ASSERT_NO_THROW(checkCode( + "struct foo;\n" + "void f() {\n" + " auto fn = []() -> foo* { return new foo(); };\n" + "}")); ignore_errout(); // we do not care about the output } }; diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 13cade82957..f0a9926b775 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -33,7 +33,7 @@ class TestInternal : public TestFixture { /*const*/ Settings settings; void run() override { - settings.addEnabled("internal"); + ASSERT_EQUALS("", settings.addEnabled("internal")); TEST_CASE(simplePatternInTokenMatch); TEST_CASE(complexPatternInTokenSimpleMatch); diff --git a/test/testio.cpp b/test/testio.cpp index 0f21343ff16..f8318c3c1c8 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -831,13 +831,13 @@ class TestIO : public TestFixture { void testFormatStrNoWarn(const char *filename, unsigned int linenr, const char (&code)[size], bool cpp = false) { check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); } template @@ -845,13 +845,13 @@ class TestIO : public TestFixture { const char (&code)[size], const char* testScanfErrString, bool cpp = false) { check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrString, errout_str()); } template @@ -859,13 +859,13 @@ class TestIO : public TestFixture { const char (&code)[size], const char* testScanfErrAkaString, const char* testScanfErrAkaWin64String, bool cpp = false) { check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str()); } template @@ -873,13 +873,13 @@ class TestIO : public TestFixture { const char (&code)[size], const char* testScanfErrAkaWin64String, bool cpp = false) { check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaWin64String, errout_str()); } template @@ -887,13 +887,13 @@ class TestIO : public TestFixture { const char (&code)[size], const char* testScanfErrAkaString, bool cpp = false) { check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); + (void)assertEquals(filename, linenr, testScanfErrAkaString, errout_str()); check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); - assertEquals(filename, linenr, emptyString, errout_str()); + (void)assertEquals(filename, linenr, emptyString, errout_str()); } #define TEST_SCANF_NOWARN(FORMAT, FORMATSTR, TYPE) \ diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index e59086b940b..6cdabd7f9b1 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -1020,8 +1020,8 @@ class TestLibrary : public TestFixture { void loadLibError(const char (&xmldata)[size], Library::ErrorCode errorcode, const char* file, unsigned line) const { Library library; Library::Error liberr; - assertEquals(file, line, true, LibraryHelper::loadxmldata(library, liberr, xmldata, size-1)); - assertEquals(file, line, true, errorcode == liberr.errorcode); + (void)assertEquals(file, line, true, LibraryHelper::loadxmldata(library, liberr, xmldata, size-1)); + (void)assertEquals(file, line, true, errorcode == liberr.errorcode); } #define LOADLIB_ERROR_INVALID_RANGE(valid) LOADLIBERROR("\n" \ diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index 3c441b8da2b..e7e6d3b047a 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -145,9 +145,9 @@ class TestMathLib : public TestFixture { ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "0"), INTERNAL, "Internal Error: Division by zero"); // decimal zero: throw ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "00"), INTERNAL, "Internal Error: Division by zero"); // octal zero: throw ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("123", "0x0"), INTERNAL, "Internal Error: Division by zero"); // hex zero: throw - MathLib::divide("123", "0.0f"); // float zero: don't throw - MathLib::divide("123", "0.0"); // double zero: don't throw - MathLib::divide("123", "0.0L"); // long double zero: don't throw + ASSERT_NO_THROW(MathLib::divide("123", "0.0f")); // float zero + ASSERT_NO_THROW(MathLib::divide("123", "0.0")); // double zero + ASSERT_NO_THROW(MathLib::divide("123", "0.0L")); // long double zero ASSERT_THROW_INTERNAL_EQUALS(MathLib::divide("-9223372036854775808", "-1"), INTERNAL, "Internal Error: Division overflow"); // #4520 - out of range => throw ASSERT_EQUALS("4611686018427387904", MathLib::divide("-9223372036854775808", "-2")); // #6679 @@ -177,7 +177,7 @@ class TestMathLib : public TestFixture { ASSERT_EQUALS("12.0", MathLib::calculate("12.0", "13.0", '%')); ASSERT_EQUALS("1.3", MathLib::calculate("5.3", "2.0", '%')); ASSERT_EQUALS("1.7", MathLib::calculate("18.5", "4.2", '%')); - MathLib::calculate("123", "0.0", '%'); // don't throw + ASSERT_NO_THROW(MathLib::calculate("123", "0.0", '%')); #endif ASSERT_THROW_INTERNAL_EQUALS(MathLib::calculate("123", "0", '%'), INTERNAL, "Internal Error: Division by zero"); // throw diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 5caf5515f94..a4bf232af6f 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -4548,7 +4548,7 @@ class TestNullPointer : public TestFixture { std::list fileInfo; Check& c = getCheck(); fileInfo.push_back(c.getFileInfo(tokenizer, settings)); - c.analyseWholeProgram(ctu, fileInfo, settings, *this); + c.analyseWholeProgram(ctu, fileInfo, settings, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); diff --git a/test/testplatform.cpp b/test/testplatform.cpp index 917e64b52c6..3507ce18cb6 100644 --- a/test/testplatform.cpp +++ b/test/testplatform.cpp @@ -402,7 +402,7 @@ class TestPlatform : public TestFixture { void limitsDefines() const { Platform platform; - platform.set(Platform::Unix64); + ASSERT_EQUALS(true, platform.set(Platform::Unix64)); const std::string defs = "CHAR_BIT=8;SCHAR_MIN=-128;SCHAR_MAX=127;UCHAR_MAX=255;CHAR_MIN=0;CHAR_MAX=127;SHRT_MIN=-32768;SHRT_MAX=32767;USHRT_MAX=65535;INT_MIN=-2147483648;INT_MAX=2147483647;UINT_MAX=4294967295;LONG_MIN=-9223372036854775808;LONG_MAX=9223372036854775807;ULONG_MAX=9223372036854775807"; const std::string defs_c99 = "CHAR_BIT=8;SCHAR_MIN=-128;SCHAR_MAX=127;UCHAR_MAX=255;CHAR_MIN=0;CHAR_MAX=127;SHRT_MIN=-32768;SHRT_MAX=32767;USHRT_MAX=65535;INT_MIN=-2147483648;INT_MAX=2147483647;UINT_MAX=4294967295;LONG_MIN=-9223372036854775808;LONG_MAX=9223372036854775807;ULONG_MAX=9223372036854775807;LLONG_MIN=-9223372036854775808;LLONG_MAX=9223372036854775807;ULLONG_MAX=9223372036854775807"; ASSERT_EQUALS(defs, platform.getLimitsDefines(Standards::cstd_t::C89)); diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 659bf930616..f69518911ef 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -347,7 +347,7 @@ class TestPreprocessor : public TestFixture { void error3() { const auto settings = dinit(Settings, $.userDefines = "__cplusplus"); const std::string code("#error hello world!\n"); - PreprocessorHelper::getcode(settings, *this, code, "X", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "X", "test.c"); ASSERT_EQUALS("[test.c:1]: (error) #error hello world!\n", errout_str()); } @@ -357,7 +357,7 @@ class TestPreprocessor : public TestFixture { { const auto settings = dinit(Settings, $.userDefines = "TEST"); const std::string code("#file \"ab.h\"\n#error hello world!\n#endfile"); - PreprocessorHelper::getcode(settings, *this, code, "TEST", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "TEST", "test.c"); ASSERT_EQUALS("[ab.h:1]: (error) #error hello world!\n", errout_str()); } @@ -365,7 +365,7 @@ class TestPreprocessor : public TestFixture { { const auto settings = dinit(Settings, $.userDefines = "TEST"); const std::string code("#file \"ab.h\"\n\n#endfile\n#error aaa"); - PreprocessorHelper::getcode(settings, *this, code, "TEST", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "TEST", "test.c"); ASSERT_EQUALS("[test.c:2]: (error) #error aaa\n", errout_str()); } } @@ -376,7 +376,7 @@ class TestPreprocessor : public TestFixture { $.userDefines = "TEST", $.force = true); const std::string code("#error hello world!\n"); - PreprocessorHelper::getcode(settings, *this, code, "X", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "X", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -1506,7 +1506,7 @@ class TestPreprocessor : public TestFixture { "}\n"; // expand macros.. - OurPreprocessor::expandMacros(filedata, this); + (void)OurPreprocessor::expandMacros(filedata, this); ASSERT_EQUALS("[file.cpp:7]: (error) No pair for character (\"). Can't process file. File is either invalid or unicode, which is currently not supported.\n", errout_str()); } @@ -1896,7 +1896,7 @@ class TestPreprocessor : public TestFixture { "// cppcheck-suppress missingIncludeSystem\n" "#include \n"); SuppressionList inlineSuppr; - PreprocessorHelper::getcode(settings, *this, code, "", "test.c", &inlineSuppr); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c", &inlineSuppr); auto suppressions = inlineSuppr.getSuppressions(); ASSERT_EQUALS(2, suppressions.size()); @@ -2271,7 +2271,7 @@ class TestPreprocessor : public TestFixture { void wrongPathOnErrorDirective() { const auto settings = dinit(Settings, $.userDefines = "foo"); const std::string code("#error hello world!\n"); - PreprocessorHelper::getcode(settings, *this, code, "X", "./././test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "X", "./././test.c"); ASSERT_EQUALS("[test.c:1]: (error) #error hello world!\n", errout_str()); } @@ -2286,7 +2286,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", ""); std::string code("#include \"header.h\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -2300,7 +2300,7 @@ class TestPreprocessor : public TestFixture { setTemplateFormat("simple"); std::string code("#include \"header.h\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str()); } @@ -2316,7 +2316,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "inc"); std::string code("#include \"header.h\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str()); } @@ -2333,7 +2333,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "inc"); std::string code("#include \"inc/header.h\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -2350,7 +2350,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", Path::getCurrentPath()); std::string code("#include \"" + header.path() + "\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -2366,7 +2366,7 @@ class TestPreprocessor : public TestFixture { const std::string header = Path::join(Path::getCurrentPath(), "header.h"); std::string code("#include \"" + header + "\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: \"" + header + "\" not found. [missingInclude]\n", errout_str()); } @@ -2382,7 +2382,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", ""); std::string code("#include "); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str()); } @@ -2396,7 +2396,7 @@ class TestPreprocessor : public TestFixture { setTemplateFormat("simple"); std::string code("#include "); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str()); } @@ -2413,7 +2413,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", "system"); std::string code("#include "); - PreprocessorHelper::getcode(settings0, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings0, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -2430,7 +2430,7 @@ class TestPreprocessor : public TestFixture { ScopedFile header("header.h", "", Path::getCurrentPath()); std::string code("#include <" + header.path() + ">"); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("", errout_str()); } @@ -2446,7 +2446,7 @@ class TestPreprocessor : public TestFixture { const std::string header = Path::join(Path::getCurrentPath(), "header.h"); std::string code("#include <" + header + ">"); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str()); } @@ -2466,7 +2466,7 @@ class TestPreprocessor : public TestFixture { "#include \n" "#include \n" "#include \"header2.h\""); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n" "test.c:2:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n" @@ -2502,7 +2502,7 @@ class TestPreprocessor : public TestFixture { "#include \"" + missing3 + "\"\n" "#include <" + header6.path() + ">\n" "#include <" + missing4 + ">\n"); - PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); + (void)PreprocessorHelper::getcode(settings, *this, code, "", "test.c"); ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n" "test.c:2:0: information: Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n" diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index bb7155382e8..15458a516c8 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -975,7 +975,7 @@ class TestSimplifyTemplate : public TestFixture { "template struct X { void f(X &x) {} };\n" "}\n" "template <> int X::Y(0);"; - tok(code); + (void)tok(code); } void template35() { // #4074 - "A<'x'> a;" is not recognized as template instantiation @@ -1068,7 +1068,7 @@ class TestSimplifyTemplate : public TestFixture { " vector> v;" " const vector vi = static_cast>(v);" "}"; - tok(code); + (void)tok(code); } void template40() { // #5055 - false negatives when there is template specialization outside struct @@ -1208,32 +1208,32 @@ class TestSimplifyTemplate : public TestFixture { } void template46() { // #5816 - tok("template struct A { static const int value = 0; }; " - "template struct B { " - " enum { value = A::value }; " - "};"); + ASSERT_NO_THROW(tok("template struct A { static const int value = 0; }; " + "template struct B { " + " enum { value = A::value }; " + "};")); ASSERT_EQUALS("", errout_str()); - tok("template struct A {}; " - "enum { e = sizeof(A) }; " - "template struct B {};"); + ASSERT_NO_THROW(tok("template struct A {}; " + "enum { e = sizeof(A) }; " + "template struct B {};")); ASSERT_EQUALS("", errout_str()); - tok("template struct A { static const int value = 0; }; " - "template struct B { typedef int type; }; " - "template struct C { " - " enum { value = A::type, int>::value }; " - "};"); + ASSERT_NO_THROW(tok("template struct A { static const int value = 0; }; " + "template struct B { typedef int type; }; " + "template struct C { " + " enum { value = A::type, int>::value }; " + "};")); ASSERT_EQUALS("", errout_str()); } void template47() { // #6023 - tok("template > class C1 {}; " - "class C2 : public C1 {};"); + ASSERT_NO_THROW(tok("template > class C1 {}; " + "class C2 : public C1 {};")); ASSERT_EQUALS("", errout_str()); } - void template48() { // #6134 - tok("template int f( { } ); " - "int foo = f<1>(0);"); + void template48() { // #6134 (hang) + (void)tok("template int f( { } ); " + "int foo = f<1>(0);"); ASSERT_EQUALS("", errout_str()); } @@ -1335,13 +1335,13 @@ class TestSimplifyTemplate : public TestFixture { ASSERT_EQUALS("", errout_str()); } - void template54() { // #6587 - tok("template _Tp* fn(); " - "template struct A { " - " template ())> " - " struct B { }; " - "}; " - "A a;"); + void template54() { // #6587 (use-after-free) + (void)tok("template _Tp* fn(); " + "template struct A { " + " template ())> " + " struct B { }; " + "}; " + "A a;"); } void template55() { // #6604 @@ -1974,7 +1974,7 @@ class TestSimplifyTemplate : public TestFixture { "template::value)>::type>\n" "void C::foo() {}"; // @todo the output is very wrong but we are only worried about the crash for now - tok(code); + (void)tok(code); } void template86() { // crash @@ -1989,7 +1989,7 @@ class TestSimplifyTemplate : public TestFixture { "S U::u;\n" "template S U::u;\n" "S &i = U::u;"; - tok(code); + (void)tok(code); } void template87() { @@ -3806,7 +3806,7 @@ class TestSimplifyTemplate : public TestFixture { "template using l = h::d, e<1 < (j)0>, f>;\n" "template void m(int, int, int) { l d; }\n" "void n() { m(0, 4, 5); }"; - tok(code); // don't crash + (void)tok(code); // don't crash } void template157() { // #9854 @@ -4048,7 +4048,7 @@ class TestSimplifyTemplate : public TestFixture { "b> d99;\n" "b> d100;"; // don't bother checking the output because this is not instantiated properly - tok(code); // don't crash + (void)tok(code); // don't crash const char code2[] = "template void f();\n" // #11489 "template void f(int);\n" @@ -4885,7 +4885,7 @@ class TestSimplifyTemplate : public TestFixture { "{\n" "};\n"; - tok(code); + (void)tok(code); //ASSERT_EQUALS("[file1.cpp:15]: (error) Internal error: failed to instantiate template. The checking continues anyway.\n", errout_str()); ASSERT_EQUALS("", errout_str()); @@ -4929,25 +4929,25 @@ class TestSimplifyTemplate : public TestFixture { void syntax_error_templates_1() { // ok code.. using ">" for a comparison - tok("xz> xyz;"); + ASSERT_NO_THROW(tok("xz> xyz;")); ASSERT_EQUALS("", errout_str()); // ok code - tok("template operator<(T a, T b) { }"); + ASSERT_NO_THROW(tok("template operator<(T a, T b) { }")); ASSERT_EQUALS("", errout_str()); // ok code (ticket #1984) - tok("void f(a) int a;\n" - "{ ;x" @@ -4962,15 +4962,15 @@ class TestSimplifyTemplate : public TestFixture { " >::type ConcreteVisitableOrDummy;\n"), SYNTAX); // code is ok, don't show syntax error - tok("struct A {int a;int b};\n" - "class Fred {" - "public:\n" - " Fred() : a({1,2}) {\n" - " for (int i=0;i<6;i++);\n" // <- no syntax error - " }\n" - "private:\n" - " A a;\n" - "};"); + ASSERT_NO_THROW(tok("struct A {int a;int b};\n" + "class Fred {" + "public:\n" + " Fred() : a({1,2}) {\n" + " for (int i=0;i<6;i++);\n" // <- no syntax error + " }\n" + "private:\n" + " A a;\n" + "};")); ASSERT_EQUALS("", errout_str()); //both of these should work but in cppcheck 2.1 only the first option will work (ticket #9843) @@ -4987,31 +4987,31 @@ class TestSimplifyTemplate : public TestFixture { } } - void template_member_ptr() { // Ticket #5786 - tok("struct A {}; " - "struct B { " - "template struct BB {}; " - "template static bool foo(int) { return true; } " - "void bar() { bool b = foo(0); }" - "};"); - tok("struct A {}; " - "struct B { " - "template struct BB {}; " - "template static bool foo(int) { return true; } " - "void bar() { bool b = foo(0); }" - "};"); - tok("struct A {}; " - "struct B { " - "template struct BB {}; " - "template static bool foo(int) { return true; } " - "void bar() { bool b = foo(0); }" - "};"); - tok("struct A {}; " - "struct B { " - "template struct BB {}; " - "template static bool foo(int) { return true; } " - "void bar() { bool b = foo(0); }" - "};"); + void template_member_ptr() { // Ticket #5786 (segmentation fault) + (void)tok("struct A {}; " + "struct B { " + "template struct BB {}; " + "template static bool foo(int) { return true; } " + "void bar() { bool b = foo(0); }" + "};"); + (void)tok("struct A {}; " + "struct B { " + "template struct BB {}; " + "template static bool foo(int) { return true; } " + "void bar() { bool b = foo(0); }" + "};"); + (void)tok("struct A {}; " + "struct B { " + "template struct BB {}; " + "template static bool foo(int) { return true; } " + "void bar() { bool b = foo(0); }" + "};"); + (void)tok("struct A {}; " + "struct B { " + "template struct BB {}; " + "template static bool foo(int) { return true; } " + "void bar() { bool b = foo(0); }" + "};"); } void template_namespace_1() { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 533b01d585a..66c7b14c009 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -1400,7 +1400,7 @@ class TestSimplifyTokens : public TestFixture { " fact2<3> ();\n" " fact2<2> ();\n" "}"; - tok(code); + (void)tok(code); } } @@ -2307,15 +2307,15 @@ class TestSimplifyTokens : public TestFixture { } void simplifyKnownVariables61() { // #7805 - tokenizeAndStringify("static const int XX = 0;\n" - "enum E { XX };\n" - "struct s {\n" - " enum Bar {\n" - " XX,\n" - " Other\n" - " };\n" - " enum { XX };\n" - "};", /*expand=*/ true); + ASSERT_NO_THROW(tokenizeAndStringify("static const int XX = 0;\n" + "enum E { XX };\n" + "struct s {\n" + " enum Bar {\n" + " XX,\n" + " Other\n" + " };\n" + " enum { XX };\n" + "};", /*expand=*/ true)); ASSERT_EQUALS("", errout_str()); } @@ -2331,9 +2331,9 @@ class TestSimplifyTokens : public TestFixture { } void simplifyKnownVariables63() { // #10798 - tokenizeAndStringify("typedef void (*a)();\n" - "enum class E { a };\n"); - ASSERT_EQUALS("", errout_str()); // don't throw + ASSERT_NO_THROW(tokenizeAndStringify("typedef void (*a)();\n" + "enum class E { a };\n")); + ASSERT_EQUALS("", errout_str()); } void simplifyKnownVariablesBailOutAssign1() { @@ -2422,7 +2422,7 @@ class TestSimplifyTokens : public TestFixture { " }\n" " return a;\n" "}\n"; - tokenizeAndStringify(code,true); + (void)tokenizeAndStringify(code,true); ASSERT_EQUALS("[test.cpp:3]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", filter_valueflow(errout_str())); // no debug warnings } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index f606bed734b..7d9fdb3c3aa 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -436,7 +436,7 @@ class TestSimplifyTypedef : public TestFixture { void cfunction3() { const char code[] = "typedef int f(int);\n" "typedef const f cf;\n"; - simplifyTypedefC(code); + (void)simplifyTypedefC(code); ASSERT_EQUALS("[file.c:2]: (portability) It is unspecified behavior to const qualify a function type.\n", errout_str()); } @@ -802,13 +802,13 @@ class TestSimplifyTypedef : public TestFixture { } void simplifyTypedef13() { - // ticket # 1167 + // ticket # 1167 (InternalError) const char code[] = "typedef std::pair Func;" "typedef std::vector CallQueue;" "int main() {}"; // Tokenize and check output.. - tok(code); + ASSERT_NO_THROW(tok(code)); ASSERT_EQUALS("", errout_str()); } @@ -852,7 +852,7 @@ class TestSimplifyTypedef : public TestFixture { } void simplifyTypedef16() { - // ticket # 1252 + // ticket # 1252 (InternalError) const char code[] = "typedef char MOT8;\n" "typedef MOT8 CHFOO[4096];\n" "typedef struct {\n" @@ -860,7 +860,7 @@ class TestSimplifyTypedef : public TestFixture { "} STRFOO;"; // Tokenize and check output.. - tok(code); + ASSERT_NO_THROW(tok(code)); ASSERT_EQUALS("", errout_str()); } @@ -1998,7 +1998,7 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef66() { // ticket #2341 const char code[] = "typedef long* GEN;\n" "extern GEN (*foo)(long);"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } @@ -2482,19 +2482,19 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef97() { // ticket #2983 (segmentation fault) const char code[] = "typedef x y\n" "(A); y"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } void simplifyTypedef99() { // ticket #2999 const char code[] = "typedef struct Fred Fred;\n" "struct Fred { };"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); const char code1[] = "struct Fred { };\n" "typedef struct Fred Fred;"; - tok(code1); + (void)tok(code1); ASSERT_EQUALS("", errout_str()); } @@ -2505,7 +2505,7 @@ class TestSimplifyTypedef : public TestFixture { " fred = se_alloc(sizeof(struct Fred));\n" " return fred;\n" "}"; - tok(code); + (void)tok(code); ASSERT_EQUALS_WITHOUT_LINENUMBERS("", errout_str()); } @@ -2521,7 +2521,7 @@ class TestSimplifyTypedef : public TestFixture { "{\n" " Fred * Fred;\n" "}"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } @@ -2531,7 +2531,7 @@ class TestSimplifyTypedef : public TestFixture { "{\n" " Fred Fred;\n" "}"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } @@ -2832,7 +2832,7 @@ class TestSimplifyTypedef : public TestFixture { void simplifyTypedef122() { // segmentation fault const char code[] = "int result = [] { return git_run_cmd(\"update-index\",\"update-index -q --refresh\"); }();"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index d6c3762fbad..5edc8d33f6a 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -478,7 +478,7 @@ class TestSimplifyUsing : public TestFixture { void simplifyUsing18() { const char code[] = "{ { { using a = a; using a; } } }"; - tok(code); // don't crash + (void)tok(code); // don't crash } void simplifyUsing19() { @@ -490,7 +490,7 @@ class TestSimplifyUsing : public TestFixture { " using b = float;\n" "}\n" "}"; - tok(code); // don't hang + (void)tok(code); // don't hang ignore_errout(); // we are not interested in the output } @@ -535,14 +535,14 @@ class TestSimplifyUsing : public TestFixture { " return nullptr;\n" "}\n" "}}}}}}}"; - tok(code); // don't hang + (void)tok(code); // don't hang ignore_errout(); // we do not care about the output } void simplifyUsing21() { const char code[] = "using a = b;\n" "enum {}"; - tok(code); // don't crash + (void)tok(code); // don't crash } void simplifyUsing22() { @@ -1327,7 +1327,7 @@ class TestSimplifyUsing : public TestFixture { " auto ret = foo::ResultCodes_e::NO_ERROR;\n" " return ret;\n" "}"; - tok(code); // don't crash + (void)tok(code); // don't crash ignore_errout(); // we do not care about the output } } @@ -1485,14 +1485,14 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS(exp, tok(code)); } - void simplifyUsing10720() { + void simplifyUsing10720() { // hang/segmentation fault const char code[] = "template \n" "struct S {};\n" "#define STAMP(thiz, prev) using thiz = S;\n" "STAMP(A, int);\n" "STAMP(B, A);\n" "STAMP(C, B);\n"; - tok(code, Platform::Type::Native, /*debugwarnings*/ true, /*preprocess*/ true); + (void)tok(code, Platform::Type::Native, /*debugwarnings*/ true, /*preprocess*/ true); ASSERT(startsWith(errout_str(), "[test.cpp:6]: (debug) Failed to parse 'using C = S < S < S < int")); } @@ -1503,7 +1503,7 @@ class TestSimplifyUsing : public TestFixture { "\n" "namespace spdlog { class logger; }\n" "using LoggerPtr = std::shared_ptr;"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } @@ -1515,7 +1515,7 @@ class TestSimplifyUsing : public TestFixture { "\n" "static void getInitialProgramState(const A::Map& vars = A::Map {})\n" "{}\n"; - tok(code); + (void)tok(code); ASSERT_EQUALS("", errout_str()); } }; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index ffb640daf9b..70bca8111db 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -6591,7 +6591,7 @@ class TestSymbolDatabase : public TestFixture { " int i = abc[ARRAY_SIZE(cats)];\n" "}"); const Token *e = Token::findsimplematch(tokenizer.tokens(), "e abc"); - db->sizeOfType(e); // <- don't crash + (void)db->sizeOfType(e); // <- don't crash } void isImplicitlyVirtual() { diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 4d6bbf83d7e..bbc1c4f20b8 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -120,8 +120,8 @@ class TestToken : public TestFixture { TokensFrontBack tokensFrontBack(list); auto *token = new Token(tokensFrontBack); token->str("1"); - token->insertToken("2"); - token->next()->insertToken("3"); + (void)token->insertToken("2"); + (void)token->next()->insertToken("3"); Token *last = token->tokAt(2); ASSERT_EQUALS(token->str(), "1"); ASSERT_EQUALS(token->strAt(1), "2"); @@ -549,7 +549,7 @@ class TestToken : public TestFixture { TokensFrontBack listEnds(list); Token ** const tokensBack = &(listEnds.back); Token tok(listEnds); - tok.insertToken("aba"); + (void)tok.insertToken("aba"); ASSERT_EQUALS(true, *tokensBack == tok.next()); tok.deleteNext(); ASSERT_EQUALS(true, *tokensBack == &tok); @@ -560,7 +560,7 @@ class TestToken : public TestFixture { Token ** const tokensFront = &(listEnds.front); Token tok(listEnds); - tok.insertToken("aba"); + (void)tok.insertToken("aba"); ASSERT_EQUALS(true, *tokensFront == tok.previous()); tok.deletePrevious(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 93bd2466131..6ffec57c4c7 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -602,7 +602,7 @@ class TestTokenizer : public TestFixture { "void f() {\n" " fpp x = (fpp)f();\n" "}"; - tokenizeAndStringify(code); + (void)tokenizeAndStringify(code); ASSERT_EQUALS("", errout_str()); } @@ -702,15 +702,15 @@ class TestTokenizer : public TestFixture { void tokenize27() { // #4525 - segfault - tokenizeAndStringify("struct except_spec_d_good : except_spec_a, except_spec_b {\n" - "~except_spec_d_good();\n" - "};\n" - "struct S { S(); };\n" - "S::S() __attribute((pure)) = default;" - ); + (void)tokenizeAndStringify("struct except_spec_d_good : except_spec_a, except_spec_b {\n" + "~except_spec_d_good();\n" + "};\n" + "struct S { S(); };\n" + "S::S() __attribute((pure)) = default;" + ); // original code: glibc-2.18/posix/bug-regex20.c - tokenizeAndStringify("static unsigned int re_string_context_at (const re_string_t *input, int idx, int eflags) internal_function __attribute__ ((pure));"); + (void)tokenizeAndStringify("static unsigned int re_string_context_at (const re_string_t *input, int idx, int eflags) internal_function __attribute__ ((pure));"); } // #3503 - don't "simplify" SetFunction member function to a variable @@ -743,7 +743,7 @@ class TestTokenizer : public TestFixture { "void z() {\n" " vector VI;\n" "}\n"; - tokenizeAndStringify(code); + (void)tokenizeAndStringify(code); } void tokenize34() { // #8031 @@ -784,8 +784,8 @@ class TestTokenizer : public TestFixture { } void tokenize35() { // #8361 - tokenizeAndStringify("typedef int CRCWord; " - "template ::CRCWord const Compute(T const t) { return 0; }"); + ASSERT_NO_THROW(tokenizeAndStringify("typedef int CRCWord; " + "template ::CRCWord const Compute(T const t) { return 0; }")); } void tokenize36() { // #8436 @@ -844,10 +844,10 @@ class TestTokenizer : public TestFixture { } void syntax_case_default() { // correct syntax - tokenizeAndStringify("void f(int n) {switch (n) { case 0: z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case 0: z(); break;}}")); ASSERT_EQUALS("", errout_str()); - tokenizeAndStringify("void f(int n) {switch (n) { case 0:; break;}}"); + (void)tokenizeAndStringify("void f(int n) {switch (n) { case 0:; break;}}"); ASSERT_EQUALS("", errout_str()); // TODO: Do not throw AST validation exception @@ -864,23 +864,23 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("", errout_str()); //'b' can be or a macro or an undefined enum - tokenizeAndStringify("void f(int n) {switch (n) { case b: z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case b: z(); break;}}")); ASSERT_EQUALS("", errout_str()); //valid, when there's this declaration: 'constexpr int g() { return 2; }' - tokenizeAndStringify("void f(int n) {switch (n) { case g(): z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case g(): z(); break;}}")); ASSERT_EQUALS("", errout_str()); //valid, when there's also this declaration: 'constexpr int g[1] = {0};' - tokenizeAndStringify("void f(int n) {switch (n) { case g[0]: z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case g[0]: z(); break;}}")); ASSERT_EQUALS("[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable g\n", errout_str()); //valid, similar to above case - tokenizeAndStringify("void f(int n) {switch (n) { case *g: z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case *g: z(); break;}}")); ASSERT_EQUALS("", errout_str()); //valid, when 'x' and 'y' are constexpr. - tokenizeAndStringify("void f(int n) {switch (n) { case sqrt(x+y): z(); break;}}"); + ASSERT_NO_THROW(tokenizeAndStringify("void f(int n) {switch (n) { case sqrt(x+y): z(); break;}}")); ASSERT_EQUALS("[test.cpp:1]: (debug) valueFlowConditionExpressions bailout: Skipping function due to incomplete variable x\n", errout_str()); } @@ -1713,18 +1713,18 @@ class TestTokenizer : public TestFixture { " int x;\n" "{}\n"), SYNTAX); - tokenizeAndStringify("void foo(int, int)\n" - "{}"); + ASSERT_NO_THROW(tokenizeAndStringify("void foo(int, int)\n" + "{}")); ASSERT_EQUALS("", errout_str()); // #3848 - Don't hang - tokenizeAndStringify("sal_Bool ShapeHasText(sal_uLong, sal_uLong) const {\n" - " return sal_True;\n" - "}\n" - "void CreateSdrOLEFromStorage() {\n" - " comphelper::EmbeddedObjectContainer aCnt( xDestStorage );\n" - " { }\n" - "}"); + (void)tokenizeAndStringify("sal_Bool ShapeHasText(sal_uLong, sal_uLong) const {\n" + " return sal_True;\n" + "}\n" + "void CreateSdrOLEFromStorage() {\n" + " comphelper::EmbeddedObjectContainer aCnt( xDestStorage );\n" + " { }\n" + "}"); ignore_errout(); } @@ -2153,7 +2153,7 @@ class TestTokenizer : public TestFixture { const char res1[] = "b < 16777216 , 10 , 24 > u ; b < 16777216 , 10 , 24 > v ;"; ASSERT_EQUALS(res1, tokenizeAndStringify(code1)); // ticket #3571 (segmentation fault) - tokenizeAndStringify("template 4) > class X4 {};"); + (void)tokenizeAndStringify("template 4) > class X4 {};"); } void vardecl_template_2() { @@ -2519,7 +2519,7 @@ class TestTokenizer : public TestFixture { } void vardecl22() { // #4211 - segmentation fault - tokenizeAndStringify("A> >* p = 0;"); + (void)tokenizeAndStringify("A> >* p = 0;"); } void vardecl23() { // #4276 - segmentation fault @@ -2555,10 +2555,10 @@ class TestTokenizer : public TestFixture { } void vardecl25() { // #4799 - segmentation fault - tokenizeAndStringify("void A::func(P g) const {}\n" - "void A::a() {\n" - " b = new d( [this]( const P & p) -> double { return this->func(p);} );\n" - "}"); + (void)tokenizeAndStringify("void A::func(P g) const {}\n" + "void A::a() {\n" + " b = new d( [this]( const P & p) -> double { return this->func(p);} );\n" + "}"); ignore_errout(); } @@ -2570,14 +2570,14 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("[test.cpp:1]: (debug) Scope::checkVariable found variable 'new' with varid 0.\n", errout_str()); } - void vardecl27() { // #7850 + void vardecl27() { // #7850 (segmentation fault) const char code[] = "extern int foo(char);\n" "void* class(char c) {\n" " if (foo(c))\n" " return 0;\n" " return 0;\n" "}"; - tokenizeAndStringify(code, /*expand=*/ true, Platform::Type::Native, false); + (void)tokenizeAndStringify(code, /*expand=*/ true, Platform::Type::Native, false); } void vardecl28() { @@ -3662,19 +3662,19 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("void foo ( ) { enum Anonymous0 : int { Six = 6 } ; return Six ; }", tokenizeAndStringify("void foo () { enum : int { Six = 6 } ; return Six ; }")); // ticket #8281 - tokenizeAndStringify("void lzma_decode(int i) { " - " bool state; " - " switch (i) " - " while (true) { " - " state=false; " - " case 1: " - " ; " - " }" - "}"); + ASSERT_NO_THROW(tokenizeAndStringify("void lzma_decode(int i) { " + " bool state; " + " switch (i) " + " while (true) { " + " state=false; " + " case 1: " + " ; " + " }" + "}")); // ticket #8417 - tokenizeAndStringify("void printOwnedAttributes(int mode) { " - " switch(mode) case 0: { break; } " - "}"); + ASSERT_NO_THROW(tokenizeAndStringify("void printOwnedAttributes(int mode) { " + " switch(mode) case 0: { break; } " + "}")); ASSERT_THROW_INTERNAL(tokenizeAndStringify("void printOwnedAttributes(int mode) { " " switch(mode) case 0: { break; } case 1: ; " "}"), @@ -4108,30 +4108,33 @@ class TestTokenizer : public TestFixture { } void cpp0xtemplate4() { // #6181, #6354, #6414 - tokenizeAndStringify("class A; " - "template class Disposer; " - "template > class Shim {}; " - "class B : public Shim {};"); - tokenizeAndStringify("template class ELFObjectImage {}; " - "ObjectImage *createObjectImage() { " - " return new ELFObjectImage>(Obj); " - "} " - "void resolveX86_64Relocation() { " - " reinterpret_cast(0); " - "}"); - tokenizeAndStringify("template " - "value_type Base(const value_type x, const value_type dx, function_type func, int type_deriv) { " - " return 0.0; " - "}; " - "namespace { " - " template class C { " - " void Fun(int G, const double x); " - " }; " - " template void C::Fun(int G, const double x) {" - " Base>(2, 2, f, 0); " - " }; " - " template class C2 {}; " - "}"); + // #6181 + ASSERT_NO_THROW(tokenizeAndStringify("class A; " + "template class Disposer; " + "template > class Shim {}; " + "class B : public Shim {};")); + // #6354 (segmentation fault) + (void)tokenizeAndStringify("template class ELFObjectImage {}; " + "ObjectImage *createObjectImage() { " + " return new ELFObjectImage>(Obj); " + "} " + "void resolveX86_64Relocation() { " + " reinterpret_cast(0); " + "}"); + // #6414 + ASSERT_NO_THROW(tokenizeAndStringify("template " + "value_type Base(const value_type x, const value_type dx, function_type func, int type_deriv) { " + " return 0.0; " + "}; " + "namespace { " + " template class C { " + " void Fun(int G, const double x); " + " }; " + " template void C::Fun(int G, const double x) {" + " Base>(2, 2, f, 0); " + " }; " + " template class C2 {}; " + "}")); ignore_errout(); } @@ -4165,8 +4168,8 @@ class TestTokenizer : public TestFixture { } void cpp14template() { // Ticket #6708 - tokenizeAndStringify("template " - "decltype(auto) forward(T& t) { return 0; }"); + (void)tokenizeAndStringify("template " + "decltype(auto) forward(T& t) { return 0; }"); ASSERT_EQUALS("[test.cpp:1]: (debug) auto token with no type.\n", errout_str()); } @@ -4618,7 +4621,7 @@ class TestTokenizer : public TestFixture { " ;\n" " }\n" "};"; - tokenizeAndStringify(code); + (void)tokenizeAndStringify(code); ASSERT_EQUALS("", errout_str()); } @@ -5947,7 +5950,7 @@ class TestTokenizer : public TestFixture { void simplifyCaseRange() { ASSERT_EQUALS("void f ( int x ) { switch ( x ) { case 1 : case 2 : case 3 : case 4 : ; } }", tokenizeAndStringify("void f(int x) { switch(x) { case 1 ... 4: } }")); ASSERT_EQUALS("void f ( int x ) { switch ( x ) { case 4 ... 1 : ; } }", tokenizeAndStringify("void f(int x) { switch(x) { case 4 ... 1: } }")); - tokenizeAndStringify("void f(int x) { switch(x) { case 1 ... 1000000: } }"); // Do not run out of memory + (void)tokenizeAndStringify("void f(int x) { switch(x) { case 1 ... 1000000: } }"); // Do not run out of memory ASSERT_EQUALS("void f ( int x ) { switch ( x ) { case 'a' : case 98 : case 'c' : ; } }", tokenizeAndStringify("void f(int x) { switch(x) { case 'a' ... 'c': } }")); ASSERT_EQUALS("void f ( int x ) { switch ( x ) { case 'c' ... 'a' : ; } }", tokenizeAndStringify("void f(int x) { switch(x) { case 'c' ... 'a': } }")); @@ -5979,7 +5982,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("a ? ( b < c ) : d > e", tokenizeAndStringify("a ? b < c : d > e")); } - enum class AstStyle : std::uint8_t { + enum class AstStyle : std :: uint8_t { Simple, Z3 }; @@ -6519,10 +6522,10 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("", errout_str()); // #10334: Do not hang! - tokenizeAndStringify("void foo(const std::vector& locations = {\"\"}) {\n" - " for (int i = 0; i <= 123; ++i)\n" - " x->emplace_back(y);\n" - "}"); + (void)tokenizeAndStringify("void foo(const std::vector& locations = {\"\"}) {\n" + " for (int i = 0; i <= 123; ++i)\n" + " x->emplace_back(y);\n" + "}"); ignore_errout(); ASSERT_NO_THROW(tokenizeAndStringify("void f() {\n" // #10831 @@ -7841,7 +7844,7 @@ class TestTokenizer : public TestFixture { void dumpAlignas() { Settings settings; SimpleTokenizer tokenizer(settings, *this); - tokenizer.tokenize("int alignas(8) alignas(16) x;", false); + ASSERT(tokenizer.tokenize("int alignas(8) alignas(16) x;", false)); ASSERT(Token::simpleMatch(tokenizer.tokens(), "int x ;")); std::ostringstream ostr; tokenizer.dump(ostr); diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 80b16002482..58789a43078 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -171,7 +171,7 @@ class TestTokenList : public TestFixture { TokenList tokenlist(&settings); std::istringstream istr(s); - tokenlist.createTokens(istr, Standards::Language::C); + ASSERT(tokenlist.createTokens(istr, Standards::Language::C)); // TODO: put this logic in TokenList // generate links { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 6aeb223a619..bf436c28f5b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -7863,7 +7863,7 @@ class TestUninitVar : public TestFixture { std::list fileInfo; Check& c = getCheck(); fileInfo.push_back(c.getFileInfo(tokenizer, settings)); - c.analyseWholeProgram(ctu, fileInfo, settings, *this); + c.analyseWholeProgram(ctu, fileInfo, settings, *this); // TODO: check result while (!fileInfo.empty()) { delete fileInfo.back(); fileInfo.pop_back(); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index ab239d0f528..599f8057f2c 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -581,7 +581,7 @@ class TestUnusedFunctions : public TestFixture { } // Check for unused functions.. - (c.check)(settings, *this); + (c.check)(settings, *this); // TODO: check result ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout_str()); } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index a67f7f2b270..bc13f92f112 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1139,7 +1139,7 @@ class TestValueFlow : public TestFixture { "auto operator<=>(const X & a, const X & b) -> decltype(1 <=> 2) {\n" " return std::strong_ordering::less;\n" "}\n"; - tokenValues(code, "<=>"); // don't throw + ASSERT_NO_THROW(tokenValues(code, "<=>")); // Comparison of string values = removeImpossible(tokenValues("f(\"xyz\" == \"xyz\");", "==")); // implementation defined @@ -3789,7 +3789,7 @@ class TestValueFlow : public TestFixture { " if (p) return;\n" " x = *p ? : 1;\n" // <- no explicit expr0 "}"; - testValueOfX(code, 1U, 0); // do not crash + (void)testValueOfX(code, 1U, 0); // do not crash code = "void f(int a) {\n" // #8784 " int x = 13;\n" @@ -4442,7 +4442,7 @@ class TestValueFlow : public TestFixture { " for(int i = 0; i < 20; i++)\n" " n = (int)(i < 10 || abs(negWander) < abs(negTravel));\n" "}"; - testValueOfX(code,0,0); // <- don't hang + (void)testValueOfX(code,0,0); // <- don't hang // crash (daca@home) code = "void foo(char *z, int n) {\n" @@ -4455,7 +4455,7 @@ class TestValueFlow : public TestFixture { " }\n" " }\n" "}"; - testValueOfX(code,0,0); // <- don't crash + (void)testValueOfX(code,0,0); // <- don't crash // conditional code in loop code = "void f(int mask) {\n" // #6000 @@ -4524,7 +4524,7 @@ class TestValueFlow : public TestFixture { " for (*&t.s.a[0] = 1;;)\n" " if (0) {}\n" "}\n"; - testValueOfX(code, 0, 0); // <- don't throw + ASSERT_NO_THROW(testValueOfX(code, 0, 0)); code = "void f() {\n" " int p[2];\n" @@ -4532,7 +4532,7 @@ class TestValueFlow : public TestFixture { " for (p[1] = 0; p[1] <= 2 - p[0]; p[1]++) {}\n" " }\n" "}\n"; - testValueOfX(code, 0, 0); // <- don't throw + ASSERT_NO_THROW(testValueOfX(code, 0, 0)); code = "struct C {\n" // #10828 " int& v() { return i; }\n" @@ -4545,7 +4545,7 @@ class TestValueFlow : public TestFixture { " for (c.v() = 0; c.v() < 24; c.v()++) {}\n" " }\n" "}\n"; - testValueOfX(code, 0, 0); // <- don't throw + ASSERT_NO_THROW(testValueOfX(code, 0, 0)); // #11072 code = "struct a {\n" @@ -4883,7 +4883,7 @@ class TestValueFlow : public TestFixture { code = "class continuous_src_time {\n" " continuous_src_time(std::complex f, double st = 0.0, double et = infinity) {}\n" "};"; - testValueOfX(code, 2U, 2); // Don't crash (#6494) + (void)testValueOfX(code, 2U, 2); // Don't crash (#6494) } bool isNotKnownValues(const char code[], const char str[]) { @@ -5296,7 +5296,7 @@ class TestValueFlow : public TestFixture { void valueFlowSizeofForwardDeclaredEnum() { const char *code = "enum E; sz=sizeof(E);"; - valueOfTok(code, "="); // Don't crash (#7775) + (void)valueOfTok(code, "="); // Don't crash (#7775) } void valueFlowGlobalVar() { @@ -7146,7 +7146,7 @@ class TestValueFlow : public TestFixture { " if (x >= -1)\n" " state = x;\n" "}\n"; - valueOfTok(code, "="); + (void)valueOfTok(code, "="); code = "void a() {\n" " auto b = [b = 0] {\n" @@ -7154,7 +7154,7 @@ class TestValueFlow : public TestFixture { " }\n" " };\n" "}\n"; - valueOfTok(code, "0"); + (void)valueOfTok(code, "0"); code = "namespace juce {\n" "PopupMenu::Item& PopupMenu::Item::operator= (Item&&) = default;\n" @@ -7164,7 +7164,7 @@ class TestValueFlow : public TestFixture { " o.isWatchingForDeletion = true;\n" " return o;\n" "}}\n"; - valueOfTok(code, "return"); + (void)valueOfTok(code, "return"); code = "class dummy_resource : public instrument_resource {\n" "public:\n" @@ -7174,7 +7174,7 @@ class TestValueFlow : public TestFixture { "void dummy_reader_reset() {\n" " dummy_resource::log.clear();\n" "}\n"; - valueOfTok(code, "log"); + (void)valueOfTok(code, "log"); code = "struct D : B {\n" " D(int i, const std::string& s) : B(i, s) {}\n" @@ -7182,7 +7182,7 @@ class TestValueFlow : public TestFixture { "template<> struct B::S {\n" " int j;\n" "};\n"; - valueOfTok(code, "B"); + (void)valueOfTok(code, "B"); } void valueFlowCrash() { @@ -7191,7 +7191,7 @@ class TestValueFlow : public TestFixture { code = "void f(int x) {\n" " if (0 * (x > 2)) {}\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "struct a {\n" " void b();\n" @@ -7202,7 +7202,7 @@ class TestValueFlow : public TestFixture { " e = &child;\n" " (*e).b();\n" "}\n"; - valueOfTok(code, "e"); + (void)valueOfTok(code, "e"); code = "const int& f(int, const int& y = 0);\n" "const int& f(int, const int& y) {\n" @@ -7212,7 +7212,7 @@ class TestValueFlow : public TestFixture { " const int& r = f(x);\n" " return r;\n" "}\n"; - valueOfTok(code, "0"); + (void)valueOfTok(code, "0"); code = "void fa(int &colors) {\n" " for (int i = 0; i != 6; ++i) {}\n" @@ -7220,7 +7220,7 @@ class TestValueFlow : public TestFixture { "void fb(not_null parent, int &&colors2) {\n" " dostuff(1);\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "void a() {\n" " static int x = 0;\n" @@ -7228,7 +7228,7 @@ class TestValueFlow : public TestFixture { " c(c &&) { ++x; }\n" " };\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "void f(){\n" " struct dwarf_data **pp;\n" @@ -7237,7 +7237,7 @@ class TestValueFlow : public TestFixture { " pp = &(*pp)->next)\n" " ;\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "void *foo(void *x);\n" "void *foo(void *x)\n" @@ -7247,7 +7247,7 @@ class TestValueFlow : public TestFixture { " return &&yes;\n" " return x;\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "void f() {\n" " std::string a = b[c->d()];\n" @@ -7256,7 +7256,7 @@ class TestValueFlow : public TestFixture { " INFO(std::string{\"b\"} + a);\n" " }\n" "}\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "class A{\n" " void f() {\n" @@ -7266,7 +7266,7 @@ class TestValueFlow : public TestFixture { " return \"\";\n" " }\n" "};\n"; - valueOfTok(code, "c"); + (void)valueOfTok(code, "c"); code = "void f() {\n" " char* p = 0;\n" @@ -7280,7 +7280,7 @@ class TestValueFlow : public TestFixture { " int *i2 = 0;\n" " if (i2) { }\n" "}\n"; - valueOfTok(code, "p"); + (void)valueOfTok(code, "p"); code = "struct a;\n" "namespace e {\n" @@ -7299,7 +7299,7 @@ class TestValueFlow : public TestFixture { " if (c.h)\n" " a *const d = arguments[c.arg];\n" "}\n"; - valueOfTok(code, "c"); + (void)valueOfTok(code, "c"); code = "void h(char* p, int s) {\n" " char *q = p+s;\n" @@ -7309,14 +7309,14 @@ class TestValueFlow : public TestFixture { " if (p < q && buf < b)\n" " diff = (buf-b);\n" "}\n"; - valueOfTok(code, "diff"); + (void)valueOfTok(code, "diff"); code = "void foo() {\n" // #10462 " std::tuple t4(5.2f, 3.1f, 2.4f, 9.1f), t5(4, 6, 9, 27);\n" " t4 = t5;\n" " ASSERT(!(t4 < t5) && t4 <= t5);\n" "}"; - valueOfTok(code, "<="); + (void)valueOfTok(code, "<="); code = "void f() {\n" " unsigned short Xoff = 10;\n" @@ -7328,7 +7328,7 @@ class TestValueFlow : public TestFixture { " Nx = last - Xoff;\n" " } while (last > 0);\n" "}\n"; - valueOfTok(code, "last"); + (void)valueOfTok(code, "last"); code = "struct a {\n" " void clear();\n" @@ -7340,7 +7340,7 @@ class TestValueFlow : public TestFixture { " a e;\n" "};\n" "void d::c(int) { e.clear(); }\n"; - valueOfTok(code, "e"); + (void)valueOfTok(code, "e"); code = "struct a {\n" " int b;\n" @@ -7354,7 +7354,7 @@ class TestValueFlow : public TestFixture { " if (g && f.c)\n" " e.d.b = g - f.c;\n" "}\n"; - valueOfTok(code, "e"); + (void)valueOfTok(code, "e"); code = "struct a {\n" " std::vector b;\n" @@ -7367,7 +7367,7 @@ class TestValueFlow : public TestFixture { " }\n" " }\n" "};\n"; - valueOfTok(code, "e"); + (void)valueOfTok(code, "e"); code = "struct a {\n" " struct b {\n" @@ -7382,7 +7382,7 @@ class TestValueFlow : public TestFixture { " h->c.get();\n" " }\n" "};\n"; - valueOfTok(code, "f.c"); + (void)valueOfTok(code, "f.c"); code = "void d(fmpz_t a, fmpz_t b) {\n" " if (fmpz_sgn(0)) {}\n" @@ -7392,7 +7392,7 @@ class TestValueFlow : public TestFixture { " f->b;\n" " d(&f->a, c);\n" "}\n"; - valueOfTok(code, "f"); + (void)valueOfTok(code, "f"); code = "struct bo {\n" " int b, c, a, d;\n" @@ -7409,29 +7409,29 @@ class TestValueFlow : public TestFixture { " return;\n" " s;\n" "}\n"; - valueOfTok(code, "s"); + (void)valueOfTok(code, "s"); code = "int f(int value) { return 0; }\n" "std::shared_ptr g() {\n" " static const std::shared_ptr x{ new M{} };\n" " return x;\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "int* g();\n" "void f() {\n" " std::cout << (void*)(std::shared_ptr{ g() }.get());\n" "}\n"; - valueOfTok(code, "."); + (void)valueOfTok(code, "."); code = "class T;\n" "struct S {\n" " void f(std::array& a);\n" "};\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "void f(const char * const x) { !!system(x); }\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "struct struct1 {\n" " int i1;\n" @@ -7445,7 +7445,7 @@ class TestValueFlow : public TestFixture { "void f() {\n" " struct2 a = { 1, 2, 3, {4,5,6,7} }; \n" "}\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "void setDeltas(int life, int age, int multiplier) {\n" " int dx = 0;\n" @@ -7459,7 +7459,7 @@ class TestValueFlow : public TestFixture { " else dy = 0;\n" " }\n" "}\n"; - valueOfTok(code, "age"); + (void)valueOfTok(code, "age"); code = "void a() {\n" " struct b {\n" @@ -7467,7 +7467,7 @@ class TestValueFlow : public TestFixture { " };\n" " for (b c : {b{}, {}}) {}\n" "}\n"; - valueOfTok(code, "c"); + (void)valueOfTok(code, "c"); code = "class T {\n" "private:\n" @@ -7476,13 +7476,13 @@ class TestValueFlow : public TestFixture { "private:\n" " std::shared_ptr m;\n" "};\n"; - valueOfTok(code, "r"); + (void)valueOfTok(code, "r"); code = "void g(int);\n" "void f(int x, int y) {\n" " g(x < y ? : 1);\n" "};\n"; - valueOfTok(code, "?"); + (void)valueOfTok(code, "?"); code = "struct C {\n" " explicit C(bool);\n" @@ -7491,23 +7491,23 @@ class TestValueFlow : public TestFixture { "void f(bool b) {\n" " const C& c = C(b) ? : C(false);\n" "};\n"; - valueOfTok(code, "?"); + (void)valueOfTok(code, "?"); code = "struct S {\n" " void g(std::vector (*f) () = nullptr);\n" "};\n"; - valueOfTok(code, "="); + (void)valueOfTok(code, "="); code = "void f(bool b) {\n" // #11627 " (*printf)(\"%s %i\", strerror(errno), b ? 0 : 1);\n" "};\n"; - valueOfTok(code, "?"); + (void)valueOfTok(code, "?"); code = "void f(int i) {\n" // #11914 " int& r = i;\n" " int& q = (&r)[0];\n" "}\n"; - valueOfTok(code, "&"); + (void)valueOfTok(code, "&"); code = "bool a(int *);\n" "void fn2(int b) {\n" @@ -7519,13 +7519,13 @@ class TestValueFlow : public TestFixture { " }\n" " }\n" "}\n"; - valueOfTok(code, "e"); + (void)valueOfTok(code, "e"); code = "void f(int a, int b, int c) {\n" " if (c && (a || a && b))\n" " if (a && b) {}\n" "}\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "void g(const char* fmt, ...);\n" // #12255 "void f(const char* fmt, const char* msg) {\n" @@ -7536,10 +7536,10 @@ class TestValueFlow : public TestFixture { " const char* q = fmt;\n" " if (*q > 0 && *q < 100) {}\n" "}\n"; - valueOfTok(code, "&&"); + (void)valueOfTok(code, "&&"); code = "void f() { int& a = *&a; }\n"; // #12511 - valueOfTok(code, "="); + (void)valueOfTok(code, "="); code = "void g(int*);\n" // #12716 "void f(int a) {\n" @@ -7549,7 +7549,7 @@ class TestValueFlow : public TestFixture { " g((int[256]) { 0 });\n" " } while (true);\n" "}\n"; - valueOfTok(code, "0"); + (void)valueOfTok(code, "0"); } void valueFlowHang() { @@ -7592,7 +7592,7 @@ class TestValueFlow : public TestFixture { " arr2[3][3] == 0.0\n" " ) {}\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "namespace {\n" "struct a {\n" @@ -7606,7 +7606,7 @@ class TestValueFlow : public TestFixture { " {{&b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b},\n" " {&b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b}}}};\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "namespace {\n" "struct a {\n" @@ -7622,7 +7622,7 @@ class TestValueFlow : public TestFixture { " {&b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b,\n" " &b}}}};\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "int &a(int &);\n" "int &b(int &);\n" @@ -7663,7 +7663,7 @@ class TestValueFlow : public TestFixture { " return d(e);\n" " return e;\n" "}\n"; - valueOfTok(code, "x"); + (void)valueOfTok(code, "x"); code = "void a() {\n" " int b = 0;\n" @@ -7672,7 +7672,7 @@ class TestValueFlow : public TestFixture { " break;\n" " } while (b < 1);\n" "}\n"; - valueOfTok(code, "b"); + (void)valueOfTok(code, "b"); code = "void ParseEvent(tinyxml2::XMLDocument& doc, std::set& retItems) {\n" " auto ParseAddItem = [&](Item* item) {\n" @@ -7695,7 +7695,7 @@ class TestValueFlow : public TestFixture { " for (auto *el = root->FirstChildElement(\"Result\"); el && !ParseAddItem(GetItem(el)); el = el->NextSiblingElement(\"Result\")) ;\n" " for (auto *el = root->FirstChildElement(\"Result\"); el && !ParseAddItem(GetItem(el)); el = el->NextSiblingElement(\"Result\")) ;\n" "}\n"; - valueOfTok(code, "root"); + (void)valueOfTok(code, "root"); code = "bool isCharPotentialOperator(char ch) {\n" " return (ispunct((unsigned char) ch)\n" @@ -7706,7 +7706,7 @@ class TestValueFlow : public TestFixture { " && ch != '#' && ch != '\\\\'\n" " && ch != '\\\'' && ch != '\\\"');\n" "}\n"; - valueOfTok(code, "return"); + (void)valueOfTok(code, "return"); code = "void heapSort() {\n" " int n = m_size;\n" @@ -7714,12 +7714,12 @@ class TestValueFlow : public TestFixture { " swap(0, n - 1);\n" " }\n" "}\n"; - valueOfTok(code, "swap"); + (void)valueOfTok(code, "swap"); code = "double a;\n" "int b, c, d, e, f, g;\n" "void h() { double i, j = i = g = f = e = d = c = b = a; }\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "double a, c;\n" "double *b;\n" @@ -7729,7 +7729,7 @@ class TestValueFlow : public TestFixture { " b[1] = a;\n" " a;\n" "}\n"; - valueOfTok(code, "a"); + (void)valueOfTok(code, "a"); code = "void f(int i, int j, int n) {\n" " if ((j == 0) != (i == 0)) {}\n" @@ -7740,7 +7740,7 @@ class TestValueFlow : public TestFixture { " n = j;\n" " }\n" "}\n"; - valueOfTok(code, "i"); + (void)valueOfTok(code, "i"); code = "void f() {\n" // #11701 " std::vector v(500);\n" @@ -7757,12 +7757,12 @@ class TestValueFlow : public TestFixture { " v[i] = 0;\n" " }\n" "}\n"; - valueOfTok(code, "i"); + (void)valueOfTok(code, "i"); code = "void f() {\n" " if (llabs(0x80000000ffffffffL) == 0x7fffffff00000001L) {}\n" "}\n"; - valueOfTok(code, "f"); + (void)valueOfTok(code, "f"); code = "struct T {\n" " T();\n" @@ -7773,7 +7773,7 @@ class TestValueFlow : public TestFixture { " static T e[64];\n" " static T f[64];\n" "};\n"; - valueOfTok(code, "("); + (void)valueOfTok(code, "("); } void valueFlowCrashConstructorInitialization() { // #9577 @@ -7788,7 +7788,7 @@ class TestValueFlow : public TestFixture { " {\n" " }\n" "}"; - valueOfTok(code, "path"); + (void)valueOfTok(code, "path"); code = "void Error()\n" "{\n" @@ -7800,7 +7800,7 @@ class TestValueFlow : public TestFixture { " {\n" " }\n" "}"; - valueOfTok(code, "path"); + (void)valueOfTok(code, "path"); code = "struct S {\n" " std::string to_string() const {\n" @@ -7812,7 +7812,7 @@ class TestValueFlow : public TestFixture { "void f(S s, std::string& str) {\n" " str += s.to_string();\n" "}\n"; - valueOfTok(code, "s"); + (void)valueOfTok(code, "s"); code = "void a(int e, int d, int c, int h) {\n" " std::vector b;\n" @@ -7821,7 +7821,7 @@ class TestValueFlow : public TestFixture { " return;\n" " if (b == f && b == f && c && e < d) {}\n" "}\n"; - valueOfTok(code, "b"); + (void)valueOfTok(code, "b"); } void valueFlowUnknownMixedOperators() { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 4a6b48bb0f1..222906177d7 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -877,7 +877,7 @@ class TestVarID : public TestFixture { void varid36() { // ticket #2980 (segmentation fault) const char code[] ="#elif A\n" "A,a