diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index 69d29b70f1bc..89eb099c183e 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -90,6 +90,12 @@ def __init__(self, defines: T.Optional[T.Dict[str, str]]): # All Clang backends can also do LLVM IR self.can_compile_suffixes.add('ll') + def get_always_args(self) -> T.List[str]: + # Force clang to fail in sanity checks if an unknwon warning option is + # user + myargs: T.List[str] = ['-Werror=unknown-warning-option'] + return super().get_always_args() + myargs + def get_crt_compile_args(self, crt_val: str) -> T.List[str]: if not isinstance(self.linker, VisualStudioLikeLinkerMixin): return [] diff --git a/unittests/internaltests.py b/unittests/internaltests.py index fb0e4a2fd0ad..9f7bfece4433 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -238,6 +238,15 @@ def test_compiler_args_class_visualstudio(self): self.assertEqual(a.to_native(copy=True), ['/nologo', '/showIncludes', '/Zc:__cplusplus', '/validate-charset-']) + def test_clang_always_args_contain_werror_unknown_warning(self): + env = get_fake_env() + linker = linkers.MoldDynamicLinker([], env, MachineChoice.HOST, '-Wl,', []) + cc = ClangCCompiler([], [], '14.0.0', MachineChoice.HOST, env, linker=linker) + + always_args = cc.get_always_args() + self.assertIn('-Werror=unknown-warning-option', always_args) + + def test_msvc_unix_args_to_native(self): # joined self.assertEqual(MSVCCompiler.unix_args_to_native(['-isystemfoo']), ['/Ifoo']) diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index a79bd6d767ee..10401e304242 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -797,8 +797,8 @@ def test_cpp_std_override(self): self.assertNotIn('-std=c++98', plain_comp) self.assertNotIn('-std=c++11', plain_comp) # Now werror - self.assertIn('-Werror', plain_comp) - self.assertNotIn('-Werror', c98_comp) + self.assertIn('-Werror', plain_comp.split()) + self.assertNotIn('-Werror', c98_comp.split()) def test_run_installed(self): if is_cygwin() or is_osx():