Skip to content

Commit

Permalink
compilers: avoid -Wunused-value compiler warning in CLikeCompiler.has…
Browse files Browse the repository at this point in the history
…_members()

Otherwise, `CFLAGS='-Wall -Werror' meson build` can fail detection:

          void bar(void) {
              struct stat foo;
              foo.st_mtim.tv_nsec;

          }
  -----------
  Command line: `cc ./project/build/meson-private/tmpqz_gi65d/testfile.c -o ./project/build/meson-private/tmpqz_gi65d/output.obj -c -O3 -Werror -Wall -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99` -> 1
  stderr:
  ./project/build/meson-private/tmpqz_gi65d/testfile.c: In function 'bar':
  ./project/build/meson-private/tmpqz_gi65d/testfile.c:45:24: error: statement with no effect [-Werror=unused-value]
     45 |             foo.st_mtim.tv_nsec;
        |             ~~~~~~~~~~~^~~~~~~~
  cc1: all warnings being treated as errors
  • Loading branch information
thom311 authored and eli-schwartz committed Sep 11, 2024
1 parent f83dca3 commit a22a50a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,12 @@ def has_members(self, typename: str, membernames: T.List[str],
if extra_args is None:
extra_args = []
# Create code that accesses all members
members = ''.join(f'foo.{member};\n' for member in membernames)
members = ''.join(f'(void) ( foo.{member} );\n' for member in membernames)
t = f'''{prefix}
void bar(void) {{
{typename} foo;
{members}
(void) foo;
}}'''
return self.compiles(t, env, extra_args=extra_args,
dependencies=dependencies)
Expand Down

0 comments on commit a22a50a

Please sign in to comment.