@@ -546,6 +546,20 @@ class TestCondition : public TestFixture {
546546 " }" );
547547 ASSERT_EQUALS (" " , errout.str ());
548548
549+ {
550+ check (" void f(Class &c) {\n "
551+ " if (c.dostuff() == 3) {}\n "
552+ " else { if (c.dostuff() == 3) {} }\n "
553+ " }" );
554+ ASSERT_EQUALS (" " , errout.str ());
555+
556+ check (" void f(const Class &c) {\n "
557+ " if (c.dostuff() == 3) {}\n "
558+ " else { if (c.dostuff() == 3) {} }\n "
559+ " }" );
560+ ASSERT_EQUALS (" [test.cpp:3]: (style) Expression is always false because 'else if' condition matches previous condition at line 2.\n " , errout.str ());
561+ }
562+
549563 check (" void f(int a, int &b) {\n "
550564 " x = x / 2;\n "
551565 " if (x < 100) { b = 1; }\n "
@@ -2091,7 +2105,7 @@ class TestCondition : public TestFixture {
20912105 ASSERT_EQUALS (" [test.cpp:2]: (style) Redundant condition: a. '!a || (a && b)' is equivalent to '!a || b'\n " , errout.str ());
20922106
20932107
2094- check (" void f() {\n "
2108+ check (" void f(const Token *tok ) {\n "
20952109 " if (!tok->next()->function() || \n "
20962110 " (tok->next()->function() && tok->next()->function()->isConstructor()));\n "
20972111 " }" );
@@ -2109,7 +2123,7 @@ class TestCondition : public TestFixture {
21092123 " }" );
21102124 ASSERT_EQUALS (" " , errout.str ());
21112125
2112- check (" void f() {\n "
2126+ check (" void f(const Token *tok ) {\n "
21132127 " if (!tok->next(1)->function(1) || \n "
21142128 " (tok->next(1)->function(1) && tok->next(1)->function(1)->isConstructor()));\n "
21152129 " }" );
0 commit comments