From ab6d77ce1b7068b6f78eed8ae4f8a44c2e607f71 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 5 Oct 2023 09:28:22 -0400 Subject: [PATCH] Enable -Wundef by default on some platforms. * Fixes https://github.com/project-chip/connectedhomeip/issues/29216 --- build/config/compiler/BUILD.gn | 1 + src/inet/InetInterface.cpp | 6 +++--- src/lib/support/CHIPArgParser.hpp | 4 ++++ src/lib/support/Pool.h | 10 +++++++--- src/lib/support/UnitTestRegistration.cpp | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index c508d657b17ab2..457d3978222cc7 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -235,6 +235,7 @@ config("strict_warnings") { cflags = [ "-Wextra", "-Wshadow", + "-Wundef", "-Wunreachable-code", "-Wvla", "-Wformat", diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index e1c14dcfde449f..4d30309752408e 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -502,7 +502,7 @@ void CloseIOCTLSocket() } } -#if __ANDROID__ +#ifdef __ANDROID__ static struct if_nameindex * backport_if_nameindex(void); static void backport_if_freenameindex(struct if_nameindex *); @@ -648,7 +648,7 @@ InterfaceIterator::~InterfaceIterator() { if (mIntfArray != nullptr) { -#if __ANDROID__ +#ifdef __ANDROID__ backport_if_freenameindex(mIntfArray); #else if_freenameindex(mIntfArray); @@ -666,7 +666,7 @@ bool InterfaceIterator::Next() { if (mIntfArray == nullptr) { -#if __ANDROID__ +#ifdef __ANDROID__ mIntfArray = backport_if_nameindex(); #else mIntfArray = if_nameindex(); diff --git a/src/lib/support/CHIPArgParser.hpp b/src/lib/support/CHIPArgParser.hpp index 2c16a03f3a9239..57c68e353f58c6 100644 --- a/src/lib/support/CHIPArgParser.hpp +++ b/src/lib/support/CHIPArgParser.hpp @@ -32,6 +32,10 @@ #include #include +#ifndef CHIP_CONFIG_NON_POSIX_LONG_OPT +#define CHIP_CONFIG_NON_POSIX_LONG_OPT 0 +#endif + namespace chip { namespace ArgParser { diff --git a/src/lib/support/Pool.h b/src/lib/support/Pool.h index 72d1a1842b0e36..c2486f0c0e20b3 100644 --- a/src/lib/support/Pool.h +++ b/src/lib/support/Pool.h @@ -324,9 +324,13 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon< #ifdef __clang__ #if __has_feature(address_sanitizer) #define __SANITIZE_ADDRESS__ 1 -#endif -#endif -#endif +#else +#define __SANITIZE_ADDRESS__ 0 +#endif // __has_feature(address_sanitizer) +#else +#define __SANITIZE_ADDRESS__ 0 +#endif // __clang__ +#endif // __SANITIZE_ADDRESS__ #if __SANITIZE_ADDRESS__ // Free all remaining objects so that ASAN can catch specific use-after-free cases. ReleaseAll(); diff --git a/src/lib/support/UnitTestRegistration.cpp b/src/lib/support/UnitTestRegistration.cpp index e706bbc891d6a5..93ea135b85a9ca 100644 --- a/src/lib/support/UnitTestRegistration.cpp +++ b/src/lib/support/UnitTestRegistration.cpp @@ -32,7 +32,7 @@ typedef struct static test_suites_t gs_test_suites; -#if __ZEPHYR__ +#ifdef __ZEPHYR__ inline static bool AlreadyExists(UnitTestTriggerFunction tests) { for (uint32_t i = 0; i < gs_test_suites.num_test_suites; ++i) @@ -50,7 +50,7 @@ CHIP_ERROR RegisterUnitTests(UnitTestTriggerFunction tests) return CHIP_ERROR_NO_MEMORY; } -#if __ZEPHYR__ +#ifdef __ZEPHYR__ // Not sure yet if it's a Zephyr bug or misconfiguration, but global constructors are called // twice on native_posix platform - by libc and by Zephyr's main thread initialization code. // This makes sure tests are not run twice for that reason.