| 1 |
# Copyright 2020-2022 David Robillard <[email protected]> |
| 2 |
# SPDX-License-Identifier: CC0-1.0 OR GPL-2.0-or-later |
| 3 |
|
| 4 |
# General code to enable approximately all warnings in GCC 12, clang, and MSVC. |
| 5 |
# |
| 6 |
# This is trivial for clang and MSVC, but GCC doesn't have an "everything" |
| 7 |
# option, so we need to enable everything we want explicitly. Wall is assumed, |
| 8 |
# but Wextra is not, for stability. |
| 9 |
# |
| 10 |
# These are collected from common.opt and c.opt in the GCC source, and manually |
| 11 |
# curated with the help of the GCC documentation. Warnings that are |
| 12 |
# application-specific, historical, or about compatibility between specific |
| 13 |
# language revisions are omitted. The intent here is to have roughly the same |
| 14 |
# meaning as clang's Weverything: extremely strict, but general. Specifically |
| 15 |
# omitted are: |
| 16 |
# |
| 17 |
# General: |
| 18 |
# |
| 19 |
# Wabi= |
| 20 |
# Waggregate-return |
| 21 |
# Walloc-size-larger-than=BYTES |
| 22 |
# Walloca-larger-than=BYTES |
| 23 |
# Wframe-larger-than=BYTES |
| 24 |
# Wlarger-than=BYTES |
| 25 |
# Wstack-usage=BYTES |
| 26 |
# Wsystem-headers |
| 27 |
# Wtraditional |
| 28 |
# Wtraditional-conversion |
| 29 |
# Wtrampolines |
| 30 |
# Wvla-larger-than=BYTES |
| 31 |
# |
| 32 |
# Build specific: |
| 33 |
# |
| 34 |
# Wpoison-system-directories |
| 35 |
# |
| 36 |
# C Specific: |
| 37 |
# |
| 38 |
# Wc11-c2x-compat |
| 39 |
# Wc90-c99-compat |
| 40 |
# Wc99-c11-compat |
| 41 |
# Wdeclaration-after-statement |
| 42 |
# Wtraditional |
| 43 |
# Wtraditional-conversion |
| 44 |
# |
| 45 |
# C++ Specific: |
| 46 |
# |
| 47 |
# Wc++0x-compat |
| 48 |
# Wc++1z-compat |
| 49 |
# Wc++2a-compat |
| 50 |
# Wctad-maybe-unsupported |
| 51 |
# Wnamespaces |
| 52 |
# Wtemplates |
| 53 |
|
| 54 |
# GCC warnings that apply to all C-family languages |
| 55 |
gcc_common_warnings = [ |
| 56 |
'-Walloc-zero', |
| 57 |
'-Walloca', |
| 58 |
'-Wanalyzer-too-complex', |
| 59 |
'-Warith-conversion', |
| 60 |
'-Warray-bounds=2', |
| 61 |
'-Wattribute-alias=2', |
| 62 |
'-Wbidi-chars=ucn', |
| 63 |
'-Wcast-align=strict', |
| 64 |
'-Wcast-function-type', |
| 65 |
'-Wcast-qual', |
| 66 |
'-Wclobbered', |
| 67 |
'-Wconversion', |
| 68 |
'-Wdate-time', |
| 69 |
'-Wdisabled-optimization', |
| 70 |
'-Wdouble-promotion', |
| 71 |
'-Wduplicated-branches', |
| 72 |
'-Wduplicated-cond', |
| 73 |
'-Wempty-body', |
| 74 |
'-Wendif-labels', |
| 75 |
'-Wfloat-equal', |
| 76 |
'-Wformat-overflow=2', |
| 77 |
'-Wformat-signedness', |
| 78 |
'-Wformat-truncation=2', |
| 79 |
'-Wformat=2', |
| 80 |
'-Wignored-qualifiers', |
| 81 |
'-Wimplicit-fallthrough=3', |
| 82 |
'-Winit-self', |
| 83 |
'-Winline', |
| 84 |
'-Winvalid-pch', |
| 85 |
'-Wlogical-op', |
| 86 |
'-Wmissing-declarations', |
| 87 |
'-Wmissing-field-initializers', |
| 88 |
'-Wmissing-include-dirs', |
| 89 |
'-Wmultichar', |
| 90 |
'-Wnormalized=nfc', |
| 91 |
'-Wnull-dereference', |
| 92 |
'-Wopenacc-parallelism', |
| 93 |
'-Woverlength-strings', |
| 94 |
'-Wpacked', |
| 95 |
'-Wpacked-bitfield-compat', |
| 96 |
'-Wpadded', |
| 97 |
'-Wpointer-arith', |
| 98 |
'-Wredundant-decls', |
| 99 |
'-Wshadow', |
| 100 |
'-Wshift-negative-value', |
| 101 |
'-Wshift-overflow=2', |
| 102 |
'-Wstack-protector', |
| 103 |
'-Wstrict-aliasing=3', |
| 104 |
'-Wstrict-overflow=5', |
| 105 |
'-Wstring-compare', |
| 106 |
'-Wstringop-overflow=3', |
| 107 |
'-Wsuggest-attribute=cold', |
| 108 |
'-Wsuggest-attribute=const', |
| 109 |
'-Wsuggest-attribute=format', |
| 110 |
'-Wsuggest-attribute=malloc', |
| 111 |
'-Wsuggest-attribute=noreturn', |
| 112 |
'-Wsuggest-attribute=pure', |
| 113 |
'-Wswitch-default', |
| 114 |
'-Wswitch-enum', |
| 115 |
'-Wtrampolines', |
| 116 |
'-Wtrivial-auto-var-init', |
| 117 |
'-Wtype-limits', |
| 118 |
'-Wundef', |
| 119 |
'-Wuninitialized', |
| 120 |
'-Wunsafe-loop-optimizations', |
| 121 |
'-Wunused', |
| 122 |
'-Wunused-const-variable=2', |
| 123 |
'-Wunused-macros', |
| 124 |
'-Wvector-operation-performance', |
| 125 |
'-Wvla', |
| 126 |
'-Wwrite-strings', |
| 127 |
] |
| 128 |
|
| 129 |
####### |
| 130 |
# C++ # |
| 131 |
####### |
| 132 |
|
| 133 |
if is_variable('cpp') |
| 134 |
all_cpp_warnings = [] |
| 135 |
|
| 136 |
if cpp.get_id() == 'clang' |
| 137 |
all_cpp_warnings += [ |
| 138 |
'-Weverything', |
| 139 |
'-Wno-c++98-compat', |
| 140 |
'-Wno-c++98-compat-pedantic' |
| 141 |
] |
| 142 |
|
| 143 |
if not meson.is_cross_build() |
| 144 |
all_cpp_warnings += [ |
| 145 |
'-Wno-poison-system-directories', |
| 146 |
] |
| 147 |
endif |
| 148 |
|
| 149 |
elif cpp.get_id() == 'gcc' |
| 150 |
all_cpp_warnings += gcc_common_warnings + [ |
| 151 |
'-Wabi-tag', |
| 152 |
'-Waligned-new=all', |
| 153 |
'-Wcatch-value=3', |
| 154 |
'-Wcomma-subscript', |
| 155 |
'-Wconditionally-supported', |
| 156 |
'-Wctor-dtor-privacy', |
| 157 |
'-Wdelete-non-virtual-dtor', |
| 158 |
'-Wdeprecated', |
| 159 |
'-Wdeprecated-copy', |
| 160 |
'-Wdeprecated-copy-dtor', |
| 161 |
'-Wdeprecated-enum-enum-conversion', |
| 162 |
'-Wdeprecated-enum-float-conversion', |
| 163 |
'-Weffc++', |
| 164 |
'-Wexpansion-to-defined', |
| 165 |
'-Wextra-semi', |
| 166 |
'-Wimport', |
| 167 |
'-Winvalid-imported-macros', |
| 168 |
'-Wmismatched-tags', |
| 169 |
'-Wmultiple-inheritance', |
| 170 |
'-Wnoexcept', |
| 171 |
'-Wnoexcept-type', |
| 172 |
'-Wnon-virtual-dtor', |
| 173 |
'-Wold-style-cast', |
| 174 |
'-Woverloaded-virtual', |
| 175 |
'-Wplacement-new=2', |
| 176 |
'-Wredundant-move', |
| 177 |
'-Wredundant-tags', |
| 178 |
'-Wregister', |
| 179 |
'-Wsign-compare', |
| 180 |
'-Wsign-promo', |
| 181 |
'-Wsized-deallocation', |
| 182 |
'-Wstrict-null-sentinel', |
| 183 |
'-Wsuggest-final-methods', |
| 184 |
'-Wsuggest-final-types', |
| 185 |
'-Wsuggest-override', |
| 186 |
'-Wuseless-cast', |
| 187 |
'-Wvirtual-inheritance', |
| 188 |
'-Wvolatile', |
| 189 |
'-Wzero-as-null-pointer-constant', |
| 190 |
] |
| 191 |
|
| 192 |
elif cpp.get_id() == 'msvc' |
| 193 |
all_cpp_warnings += [ |
| 194 |
'/Wall', |
| 195 |
'/experimental:external', |
| 196 |
'/external:W0', |
| 197 |
'/external:anglebrackets', |
| 198 |
] |
| 199 |
endif |
| 200 |
|
| 201 |
all_cpp_warnings = cpp.get_supported_arguments(all_cpp_warnings) |
| 202 |
add_global_arguments(all_cpp_warnings, language: ['cpp']) |
| 203 |
endif |