2010-10-12 19:54:39 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2010-10-12 19:54:39 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2010-10-12 19:54:39 +02:00
|
|
|
#include "checkpostfixoperator.h"
|
2022-01-27 19:03:20 +01:00
|
|
|
#include "errortypes.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "settings.h"
|
2023-01-27 08:18:32 +01:00
|
|
|
#include "fixture.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "tokenize.h"
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2022-09-16 07:15:49 +02:00
|
|
|
#include <sstream> // IWYU pragma: keep
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
class TestPostfixOperator : public TestFixture {
|
2010-10-12 19:54:39 +02:00
|
|
|
public:
|
2021-08-07 20:51:18 +02:00
|
|
|
TestPostfixOperator() : TestFixture("TestPostfixOperator") {}
|
2010-10-12 19:54:39 +02:00
|
|
|
|
|
|
|
private:
|
2015-10-07 18:33:57 +02:00
|
|
|
Settings settings;
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2021-11-29 07:34:39 +01:00
|
|
|
#define check(code) check_(code, __FILE__, __LINE__)
|
|
|
|
void check_(const char code[], const char* file, int line) {
|
2010-12-01 18:00:55 +01:00
|
|
|
// Clear the error buffer..
|
|
|
|
errout.str("");
|
|
|
|
|
2010-10-12 19:54:39 +02:00
|
|
|
// Tokenize..
|
2010-12-01 18:00:55 +01:00
|
|
|
Tokenizer tokenizer(&settings, this);
|
2010-10-12 19:54:39 +02:00
|
|
|
std::istringstream istr(code);
|
2021-11-29 07:34:39 +01:00
|
|
|
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
|
2010-10-12 19:54:39 +02:00
|
|
|
|
|
|
|
// Check for postfix operators..
|
|
|
|
CheckPostfixOperator checkPostfixOperator(&tokenizer, &settings, this);
|
|
|
|
checkPostfixOperator.postfixOperator();
|
|
|
|
}
|
|
|
|
|
2022-02-10 23:02:24 +01:00
|
|
|
void run() override {
|
2021-02-24 22:00:06 +01:00
|
|
|
settings.severity.enable(Severity::performance);
|
2015-10-07 18:33:57 +02:00
|
|
|
|
2010-10-12 19:54:39 +02:00
|
|
|
TEST_CASE(testsimple);
|
|
|
|
TEST_CASE(testfor);
|
|
|
|
TEST_CASE(testvolatile);
|
|
|
|
TEST_CASE(testiterator);
|
2010-11-04 17:54:04 +01:00
|
|
|
TEST_CASE(test2168);
|
2019-12-02 16:12:14 +01:00
|
|
|
TEST_CASE(pointerSimplest);
|
2010-12-30 14:27:05 +01:00
|
|
|
TEST_CASE(pointer); // #2321 - postincrement of pointer is OK
|
2013-03-30 13:49:56 +01:00
|
|
|
TEST_CASE(testtemplate); // #4686
|
2013-03-31 13:17:23 +02:00
|
|
|
TEST_CASE(testmember);
|
|
|
|
TEST_CASE(testcomma);
|
2018-01-21 07:26:37 +01:00
|
|
|
TEST_CASE(testauto); // #8350
|
2011-06-22 13:09:42 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testsimple() {
|
2012-07-07 20:21:08 +02:00
|
|
|
check("int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" unsigned int k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" k++;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" if(k) {\n"
|
|
|
|
" k++;\n"
|
|
|
|
" }\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" k--;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" k++;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("struct K {};"
|
2011-07-24 14:53:03 +02:00
|
|
|
"void foo()\n"
|
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" k++;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2011-07-24 14:53:03 +02:00
|
|
|
|
2013-03-31 13:17:23 +02:00
|
|
|
check("struct K {};\n"
|
|
|
|
"void foo(K& k)\n"
|
|
|
|
"{\n"
|
|
|
|
" k++;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("union K {};"
|
2011-07-24 14:53:03 +02:00
|
|
|
"void foo()\n"
|
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" k++;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2011-07-24 14:53:03 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(1);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" if(k) {\n"
|
|
|
|
" k++;\n"
|
|
|
|
" }\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(1);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" if(k) {\n"
|
|
|
|
" ++k;\n"
|
|
|
|
" }\n"
|
|
|
|
" k++;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" k--;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:5]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" ++k;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" K k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" --k;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
2019-03-27 21:42:50 +01:00
|
|
|
// #9042
|
|
|
|
check("template <class T>\n"
|
|
|
|
"class c {\n"
|
|
|
|
" int i = 0;\n"
|
|
|
|
" c() { i--; }\n"
|
|
|
|
"};\n"
|
|
|
|
"template <class T>\n"
|
|
|
|
"class s {};\n"
|
|
|
|
"using BOOL = char;");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testfor() {
|
2012-07-07 20:21:08 +02:00
|
|
|
check("int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" for ( unsigned int i=0; i <= 10; i++) {\n"
|
|
|
|
" std::cout << i << std::endl;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};\n"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" for ( K i(0); i <= 10; i++) {\n"
|
|
|
|
" std::cout << i << std::endl;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};\n"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" for ( K i(0); i <= 10; ++i) {\n"
|
|
|
|
" std::cout << i << std::endl;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};\n"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" for ( K i(10); i > 1; i--) {\n"
|
|
|
|
" std::cout << i << std::endl;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"int main(int argc, char *argv[])\n"
|
|
|
|
"{\n"
|
|
|
|
" for ( K i=10; i > 1; --i) {\n"
|
|
|
|
" std::cout << i << std::endl;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2010-10-12 19:54:39 +02:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
|
|
|
|
|
2010-10-14 19:59:10 +02:00
|
|
|
}
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testvolatile() {
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class K {};\n"
|
|
|
|
"int main()\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"{\n"
|
|
|
|
" volatile K k(0);\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" k++;\n"
|
|
|
|
" std::cout << k << std::endl;\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2018-05-10 07:40:01 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-14 19:59:10 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testiterator() {
|
2012-07-07 20:21:08 +02:00
|
|
|
check("class Base {};\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
"int main() {\n"
|
|
|
|
" std::vector<Base*> v;\n"
|
|
|
|
" v.push_back(new Base());\n"
|
|
|
|
" v.push_back(new Base());\n"
|
|
|
|
" for (std::vector<Base*>::iterator i=v.begin(); i!=v.end(); i++) {\n"
|
|
|
|
" ;;\n"
|
|
|
|
" }\n"
|
|
|
|
" v.clear();\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-14 19:59:10 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("int main() {\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
" std::vector<int> v;\n"
|
|
|
|
" std::vector<int>::iterator it;\n"
|
|
|
|
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
|
|
|
" unsigned int total = 0;\n"
|
|
|
|
" it = v.begin();\n"
|
|
|
|
" while( it != v.end() ) {\n"
|
|
|
|
" total += *it;\n"
|
|
|
|
" it++;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-14 19:59:10 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("int main() {\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
" std::vector<int> v;\n"
|
|
|
|
" std::vector<int>::const_iterator it;\n"
|
|
|
|
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
|
|
|
" unsigned int total = 0;\n"
|
|
|
|
" it = v.begin();\n"
|
|
|
|
" while( it != v.end() ) {\n"
|
|
|
|
" it++;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:8]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-14 19:59:10 +02:00
|
|
|
|
2012-07-07 20:21:08 +02:00
|
|
|
check("int main() {\n"
|
2010-10-14 19:59:10 +02:00
|
|
|
" std::vector<int> v;\n"
|
|
|
|
" std::vector<int>::iterator it;\n"
|
|
|
|
" for( int i=0; i < 10; ++i ) v.push_back(i);\n"
|
|
|
|
" unsigned int total = 0;\n"
|
|
|
|
" std::vector<int>::reverse_iterator rit;\n"
|
|
|
|
" rit= v.rend();\n"
|
|
|
|
" while( rit != v.rbegin() ) {\n"
|
|
|
|
" rit--;\n"
|
|
|
|
" }\n"
|
|
|
|
" return 0;\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"}");
|
2012-07-07 20:21:08 +02:00
|
|
|
ASSERT_EQUALS("[test.cpp:9]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
2010-10-14 19:59:10 +02:00
|
|
|
|
|
|
|
}
|
2010-10-12 19:54:39 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void test2168() {
|
2010-11-04 17:54:04 +01:00
|
|
|
check("--> declare allocator lock here\n"
|
2013-03-20 15:36:16 +01:00
|
|
|
"int main(){}");
|
2010-11-04 17:54:04 +01:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
2010-12-30 14:27:05 +01:00
|
|
|
|
2019-12-02 16:12:14 +01:00
|
|
|
void pointerSimplest() {
|
|
|
|
check("void f(int* p){\n"
|
|
|
|
" p++;\n"
|
|
|
|
" std::cout << *p;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void pointer() {
|
2010-12-30 14:27:05 +01:00
|
|
|
check("static struct class * ab;\n"
|
|
|
|
"int * p;\n"
|
2019-12-03 18:33:05 +01:00
|
|
|
"\n"
|
|
|
|
"void f() {\n"
|
|
|
|
" p++;\n"
|
2021-02-20 12:58:42 +01:00
|
|
|
"}");
|
2010-12-30 14:27:05 +01:00
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
2013-03-30 13:49:56 +01:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testtemplate() {
|
2013-03-30 13:49:56 +01:00
|
|
|
check("bool foo() {\n"
|
|
|
|
" std::vector<FilterConfigCacheEntry>::iterator aIter(aImport.begin());\n"
|
|
|
|
" aIter++;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("[test.cpp:3]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
|
|
|
}
|
2013-03-31 13:17:23 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testmember() {
|
2013-03-31 13:17:23 +02:00
|
|
|
check("bool foo() {\n"
|
|
|
|
" class A {}; class B {A a;};\n"
|
|
|
|
" B b;\n"
|
|
|
|
" b.a++;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
|
|
|
|
|
|
|
check("bool foo() {\n"
|
|
|
|
" class A {}; class B {A a;};\n"
|
|
|
|
" B b;\n"
|
|
|
|
" foo(b.a++);\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void testcomma() {
|
2013-03-31 13:17:23 +02:00
|
|
|
check("bool foo(int i) {\n"
|
|
|
|
" class A {};\n"
|
|
|
|
" A a;\n"
|
|
|
|
" i++, a++;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("[test.cpp:4]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str());
|
|
|
|
|
|
|
|
check("bool foo(int i) {\n"
|
|
|
|
" class A {};\n"
|
|
|
|
" A a;\n"
|
|
|
|
" foo(i, a++);\n"
|
|
|
|
" foo(a++, i);\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
2018-01-21 07:26:37 +01:00
|
|
|
|
|
|
|
void testauto() { // #8350
|
|
|
|
check("enum class Color { Red = 0, Green = 1, };\n"
|
|
|
|
"int fun(const Color color) {\n"
|
|
|
|
" auto a = 0;\n"
|
|
|
|
" for (auto i = static_cast<int>(color); i < 10; i++) {\n"
|
|
|
|
" a += i;\n"
|
|
|
|
" }\n"
|
|
|
|
" return a;\n"
|
|
|
|
"}");
|
|
|
|
ASSERT_EQUALS("", errout.str());
|
|
|
|
}
|
2010-10-12 19:54:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
REGISTER_TEST(TestPostfixOperator)
|