Repository: mesonbuild/meson

Issue:
Meson silently ignores compiler's warn_args for buildtype=plain
**Describe the bug**

If the `buildtype` option is set to `plain`, meson will ignore the compiler's `warn_args` (as stated in [this line](https://github.com/mesonbuild/meson/blob/d42cd735a4dc894d8e898a5f9e81029f6eb5364c/mesonbuild/backend/backends.py#L641). This way, `warning_level=<any value>` is completely thrown out (although `werror=true` still sends a `-Werror` in GCC/Clang).

In addition to that, there are two things I would like to point out:
  1. **Documentation:** There's nothing obvious describing what is each buildtype's expected scenarios. I only found out the idea behind `plain` because of a line in ["Quick-Guide"](https://mesonbuild.com/Quick-guide.html#using-meson-as-a-distro-packager), while the table in [Core Options](https://mesonbuild.com/Builtin-options.html#core-options) doesn't give any clue about it. I would appreciate some more and better documenting on this (I could help with a PR but probably would end up causing some rework, since someone would have to explain to me the internal differences between the builttypes, which is almost the same as writing the doc itself).

  2. **The current behaviour:** While discussing in `#mesonbuild`, it was mentioned that maybe it wasn't a good choice of behaviour. First because we now sort of have two ways to enable/disable the same thing (i.e. either by defining `warning_level=0` or by having `buildtype=plain`), even if one of them is some sort of a superset of the other. For this, it was stated that if someone wanted to both disable meson flags _and_ warnings, we could simply recommend to use `--buildtype=plain --warnlevel 0`. The second is that it is completely non-overrideable: if you use `buildtype=plain`, there's no way to reapply `warning_level`'s flags. For this one, maybe trying to change this could lead to unnecessary additional complexity, but further discussion could also lead to a simple solution for this.

**To Reproduce**
Have any simple meson C or C++ project, configure builddir with `buildtype=plain` and `-Dwarning_level=<number greater than 0>`. Then use `ninja -C <builddir> --verbose` to see that no `-Wall`, `-Wextra` or `-Wpedantic` flags go into compilation lines.

**Expected behavior**

There are three kind of behaviors I would expect:
- Meson still uses `warning_level` in `plain` builds;
- Meson warns me about they being ignored because it is a `plain` build;
- Meson doesn't complain of manually inserting `-Wall` on a `plain` build (but keep warning on any other buildtype).

Additionally, `werror` (as well as other flags) should be consistent with the decided behavior.

**system parameters**
* **Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)?**
  Plain (for the same computer).
* **what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)**
  Linux 5.7.5-arch1-1

* **what Python version are you using e.g. 3.8.0**
  3.8.3

* **what `meson --version`**
  0.54.3

* **what `ninja --version` if it's a Ninja build**
  1.10.0



Discussion:
As the described purpose there is for Linux distro builds and disabling flags in order to apply custom $CFLAGS (and integrate into distro tooling for the selection of release vs debug builds, etc.)... I'll reiterate what I said in IRC and point out that I don't see how disabling warnings aids us.

If upstream wants to default to those warnings, the software will still build fine, albeit a bit more noisily, as long as they don't also set -Werror. It's not clear that the advantages (?) of ignoring warning flags outweigh the disadvantages of having an additional way to ignore them, that unintuitively cannot be disabled.

Distro tooling that cares about disabling warnings can just pass one more standard meson option. Lots of non-builtin warnings might be manually added with add_project_arguments() and cannot be disabled, anyway... But meson complains if you try to do that with -Wall -Wpedantic.
Just for the reference this was changed explicitly by this commit https://github.com/mesonbuild/meson/commit/8ee1c9a07a3a35e3ed262fbc358fd86c257a966e .

Resolving patch:
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -663,7 +663,7 @@ def generate_basic_compiler_args(self, target, compiler, no_warn_args=False):
         # we weren't explicitly asked to not emit warnings (for Vala, f.ex)
         if no_warn_args:
             commands += compiler.get_no_warn_args()
-        elif self.get_option_for_target('buildtype', target) != 'plain':
+        else:
             commands += compiler.get_warn_args(self.get_option_for_target('warning_level', target))
         # Add -Werror if werror=true is set in the build options set on the
         # command-line or default_options inside project(). This only sets the


Test patch: