Compiler option updates
- Add -fdiagnostics-color so that compiler warnings are colorized. The
way Ninja invokes GCC disables colors by default.
- Move -Wno-psabi up to the arm_gcc_toolchain template so that it
doesn't have to be specified for each arm_gcc_toolchain instance.
- Add -Werror to the strict_warnings config to prevent warnings from
slipping through. Exempt a few warnings that should actually be
warnings.
Change-Id: I8656d6690b488f7b004f15abd7100b62e1945cfd
diff --git a/pw_build/BUILD.gn b/pw_build/BUILD.gn
index 75003fa..efac792 100644
--- a/pw_build/BUILD.gn
+++ b/pw_build/BUILD.gn
@@ -28,13 +28,20 @@
"-Wall",
"-Wextra",
- # Warn when a switch on an enum does not cover all the cases.
- "-Wswitch",
+ # Make all warnings errors, except for the exemptions below.
+ "-Werror",
+ "-Wno-error=cpp", # preprocessor #warning statement
+ "-Wno-error=deprecated-declarations", # [[deprecated]] attribute
]
}
config("cpp17") {
- cflags_cc = [ "-std=c++17" ]
+ cflags_cc = [
+ "-std=c++17",
+
+ # Allow uses of the register keyword, which may appear in C headers.
+ "-Wno-register",
+ ]
}
# Default C++ version for Pigweed modules.
diff --git a/pw_toolchain/BUILD.gn b/pw_toolchain/BUILD.gn
index 3b63d01..fc01d1c 100644
--- a/pw_toolchain/BUILD.gn
+++ b/pw_toolchain/BUILD.gn
@@ -79,21 +79,6 @@
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard",
"-mthumb",
-
- # Disable obnoxious ABI warning.
- #
- # GCC 7.1 adds an over-zealous ABI warning with little useful information
- # on how to resolve the issue. The warning you get is:
- #
- # note: parameter passing for argument of type '...' changed in GCC 7.1
- #
- # There is no other information, and searching for the error is needed to
- # understand what is happening. For upstream Pigweed, we compile from
- # source so this is irrelevant; so disable it.
- #
- # See: https://gcc.gnu.org/gcc-7/changes.html (search for "psabi").
- # https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html
- "-Wno-psabi",
]
common_toolchain_ldflags = [
diff --git a/pw_toolchain/arm_gcc.gni b/pw_toolchain/arm_gcc.gni
index 1b20d4f..0103607 100644
--- a/pw_toolchain/arm_gcc.gni
+++ b/pw_toolchain/arm_gcc.gni
@@ -18,11 +18,33 @@
# toolchain_cflags: Additional C/C++ compiler flags for the target.
# toolchain_ldflags: Additional linker flags for the target.
template("arm_gcc_toolchain") {
- _toolchain_cflags = ""
+ _cflags_list = [
+ # Colorize output. Ninja's GCC invocation disables color by default.
+ "-fdiagnostics-color",
+
+ # Disable obnoxious ABI warning.
+ #
+ # GCC 7.1 adds an over-zealous ABI warning with little useful information
+ # on how to resolve the issue. The warning you get is:
+ #
+ # note: parameter passing for argument of type '...' changed in GCC 7.1
+ #
+ # There is no other information, and searching for the error is needed to
+ # understand what is happening. For upstream Pigweed, we compile from
+ # source so this is irrelevant; so disable it.
+ #
+ # See: https://gcc.gnu.org/gcc-7/changes.html (search for "psabi").
+ # https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html
+ "-Wno-psabi",
+ ]
+
if (defined(invoker.toolchain_cflags)) {
- foreach(flag, invoker.toolchain_cflags) {
- _toolchain_cflags += " " + flag
- }
+ _cflags_list += invoker.toolchain_cflags
+ }
+
+ _toolchain_cflags = ""
+ foreach(flag, _cflags_list) {
+ _toolchain_cflags += " " + flag
}
_toolchain_ldflags = ""
diff --git a/pw_toolchain/x86_linux_gcc.gni b/pw_toolchain/x86_linux_gcc.gni
index fcb4926..4c6a898 100644
--- a/pw_toolchain/x86_linux_gcc.gni
+++ b/pw_toolchain/x86_linux_gcc.gni
@@ -18,11 +18,33 @@
# toolchain_cflags: Additional C/C++ compiler flags for the target.
# toolchain_ldflags: Additional linker flags for the target.
template("x86_gcc_toolchain") {
- _toolchain_cflags = ""
+ _cflags_list = [
+ # Colorize output. Ninja's GCC invocation disables color by default.
+ "-fdiagnostics-color",
+
+ # Disable obnoxious ABI warning.
+ #
+ # GCC 7.1 adds an over-zealous ABI warning with little useful information
+ # on how to resolve the issue. The warning you get is:
+ #
+ # note: parameter passing for argument of type '...' changed in GCC 7.1
+ #
+ # There is no other information, and searching for the error is needed to
+ # understand what is happening. For upstream Pigweed, we compile from
+ # source so this is irrelevant; so disable it.
+ #
+ # See: https://gcc.gnu.org/gcc-7/changes.html (search for "psabi").
+ # https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html
+ "-Wno-psabi",
+ ]
+
if (defined(invoker.toolchain_cflags)) {
- foreach(flag, invoker.toolchain_cflags) {
- _toolchain_cflags += " " + flag
- }
+ _cflags_list += invoker.toolchain_cflags
+ }
+
+ _toolchain_cflags = ""
+ foreach(flag, _cflags_list) {
+ _toolchain_cflags += " " + flag
}
_toolchain_ldflags = ""