From 9d4413d65f25279c8d0f0846322a4eae772a8bc3 Mon Sep 17 00:00:00 2001 From: pal1000 Date: Tue, 7 Feb 2023 01:35:45 +0200 Subject: [PATCH] meson: Ignore unused variables when assertions are disabled Fixes: 46b099e3 ("meson: Ignore unused variables in release builds") 46b099e3 has some issues: - it doesn't enable unused variables warning on release builds with assertions enabled; - it doesn't disable unused variables warning on debug builds with assertions disabled; - it doesn't disable unused variables warning when building with MSVC and assertions are disabled regardless of buildtype, see #8147. 3/4 regressions reported there have this limitation alone as root cause. Reviewed-by: Emma Anholt Part-of: (cherry picked from commit 4347072443867f6337c33ffc330263bb851d9839) --- .pick_status.json | 2 +- meson.build | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 61ca144a120..52c85b85bb0 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -850,7 +850,7 @@ "description": "meson: Ignore unused variables when assertions are disabled", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "46b099e3925d118b1637505b1f26de50059649aa" }, diff --git a/meson.build b/meson.build index 392f85be7f4..302fc622a98 100644 --- a/meson.build +++ b/meson.build @@ -1203,12 +1203,12 @@ else _trial_cpp += ['-ffunction-sections', '-fdata-sections'] endif - # Variables that are only used for assertions are considered unused in release - # builds. Don't treat this as an error, since we build with -Werror even for - # release in CI. - if get_option('buildtype') == 'release' - _trial_c += ['-Wno-unused-variable', '-Wno-unused-but-set-variable'] - _trial_cpp += ['-Wno-unused-variable', '-Wno-unused-but-set-variable'] + # Variables that are only used for assertions are considered unused when assertions + # are disabled. Don't treat this as an error, since we build with -Werror even if + # assertions are disabled. + if get_option('b_ndebug') == 'true' or (get_option('buildtype') == 'release' and get_option('b_ndebug') == 'if-release') + _trial_c += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189'] + _trial_cpp += ['-Wno-unused-variable', '-Wno-unused-but-set-variable', '/wd4189'] endif c_args += cc.get_supported_arguments(_trial_c)