diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c7552010c..5cee5cf2a 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1882,6 +1882,10 @@ void CheckOther::variableScopeError(const Token *tok, const std::string &varname void CheckOther::checkCommaSeparatedReturn() { + // This is experimental for now. See #5076 + if (!_settings->experimental) + return; + if (!_settings->isEnabled("style")) return; diff --git a/test/testother.cpp b/test/testother.cpp index 8306d3c53..84f9743af 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6625,38 +6625,38 @@ private: " if (a < 0)\n" " return a++,\n" " do_something();\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", errout.str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a++, do_something();\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("", errout.str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5,\n" " do_something();\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", errout.str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5, do_something();\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("", errout.str()); check("int fun(int a) {\n" " if (a < 0)\n" " return c::b;\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("", errout.str()); // ticket #4927 Segfault in CheckOther::checkCommaSeparatedReturn() on invalid code check("int main() {\n" " return 0\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("", errout.str()); // #4943 take care of C++11 initializer lists @@ -6667,7 +6667,7 @@ private: " { \"2\" },\n" " { \"3\" }\n" " };\n" - "}", NULL, false, false, false, false); + "}", NULL, true, false, false, false); ASSERT_EQUALS("", errout.str()); }