With GCC, does -Wall turn on every warning, and what do -Wextra and -Wpedantic add on top of it?
answer
- a name older than its meaning
- questionable but easy to avoid
- -Wextra: unused parameters, missing initializers
- -Wpedantic follows the chosen -std
- -Wconversion and -Wshadow are in neither
basics
~10 sNo. GCC's -Wall is a curated set of easy-to-fix warnings; -Wextra adds more, such as unused parameters; -Wpedantic reports extensions ISO C++ forbids. Useful warnings like -Wconversion and -Wshadow are in none of them.
solid answer
~30 s`-Wall` is not all warnings. The GCC manual describes it as the warnings about constructions "that some users consider questionable, and that are easy to avoid": in C++ that includes `-Wunused-variable`, `-Wreturn-type`, `-Wreorder`, `-Wsign-compare`, `-Wparentheses`, `-Wmaybe-uninitialized` and `-Wdelete-non-virtual-dtor`. `-Wextra` adds a second set: `-Wunused-parameter` (with `-Wall`), `-Wmissing-field-initializers`, `-Wimplicit-fallthrough=3`, `-Wdeprecated-copy`, `-Wredundant-move` and more. `-Wpedantic` is different in kind: it reports code that uses extensions the selected `-std` forbids. Warnings such as `-Wconversion`, `-Wsign-conversion`, `-Wshadow`, `-Wold-style-cast` and `-Wnull-dereference` are in none of these and must be named one by one.
code
cpp · 26 lines#include <cstdio>
#include <vector>
struct Sprite {
int width;
explicit Sprite(int width) : width(width) {} // GCC -Wshadow: parameter shadows member
};
int to_pixels(double metres, int scale) {
int px = metres * scale; // GCC -Wconversion: double to int
return px;
}
void on_resize(int w, int h) { // -Wall -Wextra: unused parameter 'h'
std::printf("w=%d\n", w);
}
int main() {
std::vector<int> frame_ms{16, 17, 33};
int unused = 0; // -Wall: unused variable
for (int i = 0; i < frame_ms.size(); ++i) // GCC -Wall in C++: signed/unsigned compare
std::printf("%d\n", frame_ms[i]);
on_resize(800, 600);
Sprite s(32);
std::printf("%d %d\n", to_pixels(1.5, 10), s.width);
}go deeper
Know that -Wall is a baseline, that -Wextra adds more, and that every warning names its flag in brackets so you can look it up.
Explain a few members of each set, why -Wpedantic is about ISO conformance, and how specific flags override umbrella flags.
Show you know which valuable warnings live outside both sets, such as conversion and shadowing, and the noise they cost on existing code.
Frame the choice as a team baseline: which opt-in warnings are worth their noise, and how Clang's different groups affect a dual-compiler build.
## What -Wall actually means The name is historical. The GCC 16 manual describes `-Wall` as enabling "all the warnings about constructions that some users consider questionable, and that are easy to avoid", and then lists them. It says plainly that "some warning flags are not implied by `-Wall`": some warn about code most people consider fine, others about code that is necessary or hard to change. So `-Wall` is a **curated baseline**, not a complete set. For a C++ build, the GCC 16 list includes, among many others: - `-Wunused-variable`, `-Wunused-function`, `-Wunused-but-set-variable` - `-Wreturn-type` (falling off the end of a non-void function) - `-Wreorder` (member initializers written in a different order than the members are declared) - `-Wsign-compare` (in C++ this comes with `-Wall`; in C it comes with `-Wextra`) - `-Wparentheses`, `-Wmisleading-indentation`, `-Wswitch` - `-Wmaybe-uninitialized` and `-Wuninitialized` - `-Wdelete-non-virtual-dtor`, `-Wpessimizing-move`, `-Wself-move`, `-Wrange-loop-construct` - `-Wnarrowing` and `-Woverloaded-virtual=1` Some entries only work with optimization: the manual marks `-Warray-bounds=1` as "only with `-O2`". ## What -Wextra adds `-Wextra` (formerly spelled `-W`) enables "some extra warning flags that are not enabled by `-Wall`". For C++ the GCC 16 list includes: - `-Wunused-parameter`, which fires only when `-Wall` or `-Wunused` is also on - `-Wmissing-field-initializers` and `-Wimplicit-fallthrough=3` - `-Wdeprecated-copy`, `-Wredundant-move`, `-Wdangling-reference` and `-Wsized-deallocation` - `-Wtype-limits`, `-Wempty-body`, `-Wignored-qualifiers` and `-Wcast-function-type` It also warns about a few cases with no flag of their own, such as a base class not initialized in a derived class's copy constructor. ## -Wpedantic is a different kind of flag `-Wpedantic` (also `-pedantic`) issues "all the warnings demanded by strict ISO C and ISO C++" and diagnoses programs that use forbidden extensions, following the `-std=` you selected. With `-std=gnu++20` or `-std=c++20`, GNU extensions such as variable-length arrays in C++ or zero-length arrays are accepted silently without it; with it they are diagnosed, and `-pedantic-errors` turns those into errors. It is about **conformance**, not code quality. ## What none of them turn on | Flag | What it reports | In `-Wall`? | In `-Wextra`? | |---|---|---|---| | `-Wconversion` | implicit conversions that may change a value | no | no | | `-Wsign-conversion` | implicit signed/unsigned changes (C++) | no | no | | `-Wshadow` | a declaration hiding another variable or member | no | no | | `-Wold-style-cast` | C-style casts in C++ | no | no | | `-Wnull-dereference` | paths that dereference null | no | no | | `-Wnon-virtual-dtor` | polymorphic class without virtual destructor | no | no | | `-Wuseless-cast` | a cast to the expression's own type | no | no | A team that wants these must add them by name. ## How the flags combine 1. `-Wall` and `-Wextra` are **umbrella** flags that turn on other flags, some of which turn on further ones. 2. The manual's rule: "more specific options have priority over less specific ones, independently of their position in the command line". So `-Wno-unused-parameter -Wextra` still leaves unused-parameter warnings off. 3. For options of the same specificity, the last one wins. 4. Every controllable warning prints its controlling option in brackets, which is the name to use with `-Wno-`, `-Werror=` or a pragma. ## Clang is close, not identical Clang accepts `-Wall`, `-Wextra` and `-Wpedantic` too, but its groups are its own. Running Apple clang 21 on the example below, `-Wall` alone did not report the signed/unsigned loop comparison; adding `-Wextra` did. Clang also has `-Weverything`, which GCC does not. A flag set tuned on one compiler is not automatically equivalent on the other.
- Why does GCC not put every warning into -Wall?The manual says some warnings flag code most users do not consider questionable, and others flag constructs that are necessary or hard to avoid with no simple rewrite to silence them. Putting those in the default set would bury real problems under noise, so they stay opt-in and a team enables them deliberately.
- You pass -Wextra but never see unused-parameter warnings; why?In GCC, `-Wunused-parameter` from `-Wextra` only fires together with `-Wunused` or `-Wall`. Passing `-Wall -Wextra` turns it on. A more specific `-Wno-unused-parameter` anywhere on the command line also wins over the umbrella flags, regardless of order.
- Does a clean -Wall -Wextra build mean the code is conversion-safe?No. Neither umbrella enables `-Wconversion` or, in C++, `-Wsign-conversion`, so a `double` silently truncated to `int` or a negative `int` turned into a huge `unsigned` passes both. Those flags have to be added by name, and they are usually noisy on older code.
- -Wall enables every warning GCC implements
- -Wextra replaces -Wall, so passing both is redundant
- -Wpedantic checks code style such as naming and casts
- A clean -Wall build rules out lossy implicit conversions
- Flag order decides whether -Wno-unused-parameter beats -Wextra
Assumes GCC 16.2; the members of -Wall and -Wextra listed here are taken from its manual, and the sets grow between releases.