diff --git a/analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py b/analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py index 2feccddbd0..0715dbcc51 100644 --- a/analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py +++ b/analyzer/codechecker_analyzer/analyzers/clangtidy/analyzer.py @@ -392,6 +392,8 @@ def get_checker_list(self, config) -> Tuple[List[str], List[str]]: if state == CheckerState.enabled: compiler_warnings.add('-W' + warning_name) enabled_checkers.add(checker_name) + else: + compiler_warnings.add('-Wno-' + warning_name) continue @@ -490,6 +492,8 @@ def construct_analyzer_cmd(self, result_handler): if config.enable_all: analyzer_cmd.append("-Weverything") + analyzer_cmd.extend( + filter(lambda x: x.startswith('-Wno-'), compiler_warnings)) else: analyzer_cmd.extend(compiler_warnings) diff --git a/analyzer/tests/unit/test_checker_handling.py b/analyzer/tests/unit/test_checker_handling.py index 2dd22b4845..f3c521ed84 100644 --- a/analyzer/tests/unit/test_checker_handling.py +++ b/analyzer/tests/unit/test_checker_handling.py @@ -396,6 +396,33 @@ def test_disable_clangsa_checkers(self): analyzer.config_handler.checks()['Wreserved-id-macro'][0], CheckerState.enabled) + def test_enable_all_disable_warning(self): + """ + If --enable-all is used and a warning is disabled, then the proper + parameterization of clang-tidy is using both -Weverything and + -Wno- in this order. + Side note: we use -Weverything instead of listing all enabled warnings + to represent --enable-all. + """ + args = Namespace() + args.ordered_checkers = [('clang-diagnostic-unused-variable', False)] + args.enable_all = True + + analyzer = create_analyzer_tidy(args) + result_handler = create_result_handler(analyzer) + + analyzer_cmd = analyzer.construct_analyzer_cmd(result_handler) + + try: + pos_everything = analyzer_cmd.index('-Weverything') + pos_disable = analyzer_cmd.index('-Wno-unused-variable') + self.assertLess(pos_everything, pos_disable) + except ValueError: + self.assertTrue( + False, + "-Weverything and -Wno-unused-variable should be in the " + "analysis command.") + def test_default_checkers_are_not_disabled(self): """ Test that the default checks are not disabled in Clang Tidy.