"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/testsimplifytypedef.cpp" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

testsimplifytypedef.cpp  (cppcheck-1.86):testsimplifytypedef.cpp  (cppcheck-1.87)
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team. * Copyright (C) 2007-2019 Cppcheck team.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 38 skipping to change at line 38
class TestSimplifyTypedef : public TestFixture { class TestSimplifyTypedef : public TestFixture {
public: public:
TestSimplifyTypedef() : TestFixture("TestSimplifyTypedef") { TestSimplifyTypedef() : TestFixture("TestSimplifyTypedef") {
} }
private: private:
Settings settings0; Settings settings0;
Settings settings1; Settings settings1;
Settings settings2; Settings settings2;
void run() override { void run() OVERRIDE {
settings0.addEnabled("style"); settings0.addEnabled("style");
settings2.addEnabled("style"); settings2.addEnabled("style");
TEST_CASE(simplifyTypedef1) TEST_CASE(simplifyTypedef1)
TEST_CASE(simplifyTypedef2) TEST_CASE(simplifyTypedef2)
TEST_CASE(simplifyTypedef3) TEST_CASE(simplifyTypedef3)
TEST_CASE(simplifyTypedef4) TEST_CASE(simplifyTypedef4)
TEST_CASE(simplifyTypedef5) TEST_CASE(simplifyTypedef5)
TEST_CASE(simplifyTypedef6) TEST_CASE(simplifyTypedef6)
TEST_CASE(simplifyTypedef7); TEST_CASE(simplifyTypedef7);
skipping to change at line 163 skipping to change at line 163
TEST_CASE(simplifyTypedef116); // ticket #5624 TEST_CASE(simplifyTypedef116); // ticket #5624
TEST_CASE(simplifyTypedef117); // ticket #6507 TEST_CASE(simplifyTypedef117); // ticket #6507
TEST_CASE(simplifyTypedef118); // ticket #5749 TEST_CASE(simplifyTypedef118); // ticket #5749
TEST_CASE(simplifyTypedef119); // ticket #7541 TEST_CASE(simplifyTypedef119); // ticket #7541
TEST_CASE(simplifyTypedef120); // ticket #8357 TEST_CASE(simplifyTypedef120); // ticket #8357
TEST_CASE(simplifyTypedef121); // ticket #5766 TEST_CASE(simplifyTypedef121); // ticket #5766
TEST_CASE(simplifyTypedef122); // segmentation fault TEST_CASE(simplifyTypedef122); // segmentation fault
TEST_CASE(simplifyTypedef123); // ticket #7406 TEST_CASE(simplifyTypedef123); // ticket #7406
TEST_CASE(simplifyTypedef124); // ticket #7792 TEST_CASE(simplifyTypedef124); // ticket #7792
TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[ 1]; TEST_CASE(simplifyTypedef125); // #8749 - typedef char A[10]; p = new A[ 1];
TEST_CASE(simplifyTypedef126); // ticket #5953
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
TEST_CASE(simplifyTypedefFunction3); TEST_CASE(simplifyTypedefFunction3);
TEST_CASE(simplifyTypedefFunction4); TEST_CASE(simplifyTypedefFunction4);
TEST_CASE(simplifyTypedefFunction5); TEST_CASE(simplifyTypedefFunction5);
TEST_CASE(simplifyTypedefFunction6); TEST_CASE(simplifyTypedefFunction6);
TEST_CASE(simplifyTypedefFunction7); TEST_CASE(simplifyTypedefFunction7);
TEST_CASE(simplifyTypedefFunction8); TEST_CASE(simplifyTypedefFunction8);
TEST_CASE(simplifyTypedefFunction9); TEST_CASE(simplifyTypedefFunction9);
skipping to change at line 2304 skipping to change at line 2305
"} " "} "
"}"; "}";
ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false)); ASSERT_EQUALS(expected, tok(code, true, Settings::Native, false));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef111() { // ticket #6345 void simplifyTypedef111() { // ticket #6345
const char code1[] = "typedef typename A B;\n" const char code1[] = "typedef typename A B;\n"
"typedef typename B C;\n" "typedef typename B C;\n"
"typename C c;\n"; "typename C c;\n";
const char expected1[] = "typename A c ;"; const char expected1[] = "A c ;";
ASSERT_EQUALS(expected1, tok(code1)); ASSERT_EQUALS(expected1, tok(code1));
const char code2[] = "typedef typename A B;\n" const char code2[] = "typedef typename A B;\n"
"typedef typename B C;\n" "typedef typename B C;\n"
"C c;\n"; "C c;\n";
const char expected2[] = "typename A c ;"; const char expected2[] = "A c ;";
ASSERT_EQUALS(expected2, tok(code2)); ASSERT_EQUALS(expected2, tok(code2));
const char code3[] = "typedef typename A B;\n" const char code3[] = "typedef typename A B;\n"
"typedef B C;\n" "typedef B C;\n"
"C c;\n"; "C c;\n";
const char expected3[] = "typename A c ;"; const char expected3[] = "A c ;";
ASSERT_EQUALS(expected3, tok(code3)); ASSERT_EQUALS(expected3, tok(code3));
const char code4[] = "typedef A B;\n" const char code4[] = "typedef A B;\n"
"typedef typename B C;\n" "typedef typename B C;\n"
"C c;\n"; "C c;\n";
const char expected4[] = "typename A c ;"; const char expected4[] = "A c ;";
ASSERT_EQUALS(expected4, tok(code4)); ASSERT_EQUALS(expected4, tok(code4));
const char code5[] = "typedef A B;\n" const char code5[] = "typedef A B;\n"
"typedef B C;\n" "typedef B C;\n"
"C c;\n"; "C c;\n";
const char expected5[] = "A c ;"; const char expected5[] = "A c ;";
ASSERT_EQUALS(expected5, tok(code5)); ASSERT_EQUALS(expected5, tok(code5));
// #5614 // #5614
const char code5614[] = "typedef typename T::U V;\n" const char code5614[] = "typedef typename T::U V;\n"
skipping to change at line 2530 skipping to change at line 2531
} }
void simplifyTypedef125() { // #8749 void simplifyTypedef125() { // #8749
const char code[] = "typedef char A[3];\n" const char code[] = "typedef char A[3];\n"
"char (*p)[3] = new A[4];"; "char (*p)[3] = new A[4];";
const char exp [] = "char ( * p ) [ 3 ] = new char [ 4 ] [ 3 ] ;"; const char exp [] = "char ( * p ) [ 3 ] = new char [ 4 ] [ 3 ] ;";
ASSERT_EQUALS(exp, tok(code, false)); ASSERT_EQUALS(exp, tok(code, false));
} }
void simplifyTypedef126() { // #5953
const char code[] = "typedef char automap_data_t[100];\n"
"void write_array(automap_data_t *data) {}";
const char exp [] = "void write_array ( char ( * data ) [ 100 ] ) { }";
ASSERT_EQUALS(exp, tok(code, false));
}
void simplifyTypedefFunction1() { void simplifyTypedefFunction1() {
{ {
const char code[] = "typedef void (*my_func)();\n" const char code[] = "typedef void (*my_func)();\n"
"std::queue<my_func> func_queue;"; "std::queue<my_func> func_queue;";
// The expected result.. // The expected result..
const char expected[] = "std :: queue < void ( * ) ( ) > func_queue ;"; const char expected[] = "std :: queue < void ( * ) ( ) > func_queue ;";
ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
 End of changes. 8 change blocks. 
6 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)