Repository: mesonbuild/meson

Issue:
Tests for flags fail on clang with -Weverything -Werror due to missing variable declarations
Setting C/CXXFLAGS to "-Weverything -Werror" causes checks for compiler flags (e.g., `cc.has_argument('-fopenmp-simd')`) to always fail because the test Meson uses to check the flag uses an undeclared variable, which triggers clang's `-Wmissing-variable-declarations` diagnostic.

I'm not sure when -Wmissing-variable-declarations was added to clang, but it is definitiely included in 10.0.

I can't imagine you need any help reproducing this, but if you do you can use [SIMDe](https://github.com/nemequ/simde).

Here is the relevant output from meson-logs/meson-log.txt:

```
Running compile:
Working directory:  /home/nemequ/local/src/simde/build/meson-private/tmpfvjq1jts
Command line:  clang /home/nemequ/local/src/simde/build/meson-private/tmpfvjq1jts/testfile.c -o /home/nemequ/local/src/simde/build/meson-private/tmpfvjq1jts/output.obj -pipe -c -Weverything -Werror -D_FILE_OFFSET_BITS=64 -O0 -Werror=unknown-warning-option -Werror=unused-command-line-argument -Werror=ignored-optimization-argument -fopenmp-simd 

Code:
 int i;

Compiler stdout:
 
Compiler stderr:
 /home/nemequ/local/src/simde/build/meson-private/tmpfvjq1jts/testfile.c:1:5: error: no previous extern declaration for non-static variable 'i' [-Werror,-Wmissing-variable-declarations]
int i;
    ^
/home/nemequ/local/src/simde/build/meson-private/tmpfvjq1jts/testfile.c:1:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit
int i;
^
1 error generated.

Compiler for C supports arguments -fopenmp-simd: NO 
```

Note that `-Wc++98-compat-pedantic` is also triggered by the missing newline, which causes checks for OpenMP to fail.  I suspect that this is the same root issue, and that is just the C++ manifestation.


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -1008,7 +1008,7 @@ def find_library_impl(self, libname, env, extra_dirs, code, libtype: LibType):
         return value[:]
 
     def find_library(self, libname, env, extra_dirs, libtype: LibType = LibType.PREFER_SHARED):
-        code = 'int main(void) { return 0; }'
+        code = 'int main(void) { return 0; }\n'
         return self.find_library_impl(libname, env, extra_dirs, code, libtype)
 
     def find_framework_paths(self, env):
@@ -1108,7 +1108,7 @@ def has_multi_arguments(self, args, env):
                              'the compiler you are using. has_link_argument or '
                              'other similar method can be used instead.'
                              .format(arg))
-        code = 'int i;\n'
+        code = 'extern int i;\nint i;\n'
         return self.has_arguments(args, env, code, mode='compile')
 
     def has_multi_link_arguments(self, args, env):
@@ -1117,7 +1117,7 @@ def has_multi_link_arguments(self, args, env):
         # false positive.
         args = self.linker.fatal_warnings() + args
         args = self.linker_to_compiler_args(args)
-        code = 'int main(void) { return 0; }'
+        code = 'int main(void) { return 0; }\n'
         return self.has_arguments(args, env, code, mode='link')
 
     @staticmethod


Test patch: