Git commit bebeb51b5eb53cc66b2d0085424c5df391989ae1 by Sergio Martins. Committed on 31/03/2017 at 23:55. Pushed by smartins into branch '1.1'. Introduce CLAZY_NO_WERROR env variable Set it to anything so that clazy doesn't treat warnings as errors even if -Werror is present. Useful if you want -Werror only for the regular gcc/clang warnings and not for clazy warnings. M +2 -1 src/checkbase.cpp M +3 -0 src/checkmanager.cpp M +6 -0 src/checkmanager.h M +7 -0 tests/clazy/config.json A +13 -0 tests/clazy/werror2.cpp [License: UNKNOWN] * A +1 -0 tests/clazy/werror2.cpp.expected M +6 -3 tests/run_tests.py The files marked with a * at the end have a non valid license. Please read:= http://techbase.kde.org/Policies/Licensing_Policy and use the headers whic= h are listed at that page. https://commits.kde.org/clazy/bebeb51b5eb53cc66b2d0085424c5df391989ae1 diff --git a/src/checkbase.cpp b/src/checkbase.cpp index 624fd05..689bde1 100644 --- a/src/checkbase.cpp +++ b/src/checkbase.cpp @@ -217,7 +217,8 @@ void CheckBase::reallyEmitWarning(clang::SourceLocation= loc, const std::string & { FullSourceLoc full(loc, sm()); auto &engine =3D m_ci.getDiagnostics(); - auto severity =3D engine.getWarningsAsErrors() ? DiagnosticIDs::Error = : DiagnosticIDs::Warning; + auto severity =3D (engine.getWarningsAsErrors() && !m_checkManager->us= erDisabledWError()) ? DiagnosticIDs::Error + = : DiagnosticIDs::Warning; unsigned id =3D engine.getDiagnosticIDs()->getCustomDiagID(severity, e= rror.c_str()); DiagnosticBuilder B =3D engine.Report(full, id); for (const FixItHint& fixit : fixits) { diff --git a/src/checkmanager.cpp b/src/checkmanager.cpp index a61e149..7525e98 100644 --- a/src/checkmanager.cpp +++ b/src/checkmanager.cpp @@ -51,6 +51,9 @@ CheckManager::CheckManager() m_requestedFixitName =3D string(fixitsEnv); } } + + // Allows user to make clazy ignore -Werror + m_noWerror =3D getenv("CLAZY_NO_WERROR") !=3D nullptr; } = bool CheckManager::checkExists(const string &name) const diff --git a/src/checkmanager.h b/src/checkmanager.h index 02854a0..79fa17a 100644 --- a/src/checkmanager.h +++ b/src/checkmanager.h @@ -118,6 +118,11 @@ public: return !ci.getPreprocessorOpts().ImplicitPCHInclude.empty(); } = + bool userDisabledWError() const + { + return m_noWerror; + } + private: CheckManager(); = @@ -131,6 +136,7 @@ private: std::unordered_map m_fixitByName; std::string m_requestedFixitName; bool m_enableAllFixits; + bool m_noWerror =3D false; CheckLevel m_requestedLevel; const std::vector m_extraOptions; SuppressionManager m_suppressionManager; diff --git a/tests/clazy/config.json b/tests/clazy/config.json index d4e1f4d..b108701 100644 --- a/tests/clazy/config.json +++ b/tests/clazy/config.json @@ -18,7 +18,14 @@ { "filename" : "werror.cpp", "flags" : "-Werror", + "must_fail": true, "checks" : ["foreach"] + }, + { + "filename" : "werror2.cpp", + "flags" : "-Werror", + "checks" : ["foreach"], + "env" : { "CLAZY_NO_WERROR" : "1" } } ] } diff --git a/tests/clazy/werror2.cpp b/tests/clazy/werror2.cpp new file mode 100644 index 0000000..7e73ff0 --- /dev/null +++ b/tests/clazy/werror2.cpp @@ -0,0 +1,13 @@ +#include +#include + +struct BigTrivial +{ + int a, b, c, d, e; +}; + +void test() +{ + QList list; + foreach (BigTrivial b, list) { } +} diff --git a/tests/clazy/werror2.cpp.expected b/tests/clazy/werror2.cpp.exp= ected new file mode 100644 index 0000000..ddd1921 --- /dev/null +++ b/tests/clazy/werror2.cpp.expected @@ -0,0 +1 @@ +clazy/werror2.cpp:12:14: warning: Missing reference in foreach with sizeof= (T) =3D 20 bytes (struct BigTrivial) [-Wclazy-foreach] diff --git a/tests/run_tests.py b/tests/run_tests.py index ceea7f5..96bacb8 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -30,6 +30,7 @@ class Test: self.env =3D os.environ self.checks =3D [] self.flags =3D "" + self.must_fail =3D False self.blacklist_platforms =3D [] = def isScript(self): @@ -137,6 +138,8 @@ def load_json(check_name): test.checks =3D t['checks'] if 'flags' in t: test.flags =3D t['flags'] + if 'must_fail' in t: + test.must_fail =3D t['must_fail'] if 'expects_failure' in t: test.expects_failure =3D t['expects_failure'] = @@ -339,17 +342,17 @@ def run_unit_test(test): if _verbose: print "Running: " + clazy_cmd = - using_werror =3D "-Werror" in test.flags + must_fail =3D test.must_fail = cmd_success =3D run_command(clazy_cmd, output_file, test.env) = - if (not cmd_success and not using_werror) or (cmd_success and using_we= rror): + if (not cmd_success and not must_fail) or (cmd_success and must_fail): print "[FAIL] " + checkname + " (Failed to build test. Check " + o= utput_file + " for details)" print return False = if not test.compare_everything and not test.isFixedFile: - word_to_grep =3D "warning:" if not using_werror else "error:" + word_to_grep =3D "warning:" if not must_fail else "error:" extract_word(word_to_grep, output_file, result_file) = printableName =3D checkname