Re: -Wall

Liviu Ionescu <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>

> On 19 Jan 2024, at 14:55, Corinna Vinschen <[email protected]> wrote:
> 
> ... I only found a bug because I used -Wall ...

For completeness, please note that `-Wall` does not enable **all* warnings, GCC has additional warnings, that might be useful to spot other bugs.

Below is an excerpt from my CMake scripts.

I did not check recent GCC releases, they probably include even more warnings.

Personally I'd use as many of them when `--enable-warnings`.

Regards,

Liviu


```
if("${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER_EQUAL "7.0.0")

# message(VERBOSE "Adding GCC 7 warnings...")

list(APPEND ${variable_name}

# ---------------------------------------------------------------------
# Common GNU C & C++.

-Waggregate-return
-Wcast-align
-Wcast-qual
-Wconversion
-Wdouble-promotion
-Wduplicated-branches
-Wduplicated-cond
-Wextra
-Wfloat-conversion
-Wfloat-equal
-Wformat-nonliteral
-Wformat-overflow=2
-Wformat-security
-Wformat-signedness
-Wformat-truncation=2
-Wformat-y2k
-Wformat=2
-Wlogical-op
-Wmissing-declarations
# Older GCC may include non-existent SDK folders.
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wmissing-include-dirs>
-Wnull-dereference
-Wpacked
-Wpadded
-Wpointer-arith
-Wredundant-decls
-Wshadow
-Wshift-overflow=2
-Wsign-conversion
-Wswitch-default
-Wswitch-enum
-Wundef
-Wuninitialized
-Wvla

# ---------------------------------------------------------------------
# GNU C only.

$<$<COMPILE_LANGUAGE:C>:-Wbad-function-cast>
$<$<COMPILE_LANGUAGE:C>:-Wc++-compat>
$<$<COMPILE_LANGUAGE:C>:-Wduplicate-decl-specifier>
$<$<COMPILE_LANGUAGE:C>:-Wmissing-prototypes>
$<$<COMPILE_LANGUAGE:C>:-Wnested-externs>
$<$<COMPILE_LANGUAGE:C>:-Wold-style-definition>
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>

# ---------------------------------------------------------------------
# GNU C++ only.

# inherits the "cxx11" ABI tag that 'std::string'
# $<$<COMPILE_LANGUAGE:CXX>:-Wabi-tag>

$<$<COMPILE_LANGUAGE:CXX>:-Wctor-dtor-privacy>
$<$<COMPILE_LANGUAGE:CXX>:-Wnoexcept>
$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast>
$<$<COMPILE_LANGUAGE:CXX>:-Woverloaded-virtual>
$<$<COMPILE_LANGUAGE:CXX>:-Wplacement-new=2>
$<$<COMPILE_LANGUAGE:CXX>:-Wregister>
$<$<COMPILE_LANGUAGE:CXX>:-Wsign-promo>
$<$<COMPILE_LANGUAGE:CXX>:-Wstrict-null-sentinel>
$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-final-methods>
$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-final-types>
$<$<COMPILE_LANGUAGE:CXX>:-Wsuggest-override>
$<$<COMPILE_LANGUAGE:CXX>:-Wuseless-cast>
$<$<COMPILE_LANGUAGE:CXX>:-Wzero-as-null-pointer-constant>
)

endif()

if("${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER_EQUAL "8.0.0")

# message(VERBOSE "Adding GCC 8 warnings...")

list(APPEND ${variable_name}

$<$<COMPILE_LANGUAGE:CXX>:-Wextra-semi>

)

endif()

if("${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER_EQUAL "9.0.0")

# message(VERBOSE "Adding GCC 9 warnings...")

list(APPEND ${variable_name}

# None so far.
)

endif()

if("${CMAKE_C_COMPILER_VERSION}" VERSION_GREATER_EQUAL "10.0.0")

# message(VERBOSE "Adding GCC 10 warnings...")

list(APPEND ${variable_name}

# ---------------------------------------------------------------------
# Common GNU C & C++.

-Warith-conversion

# ---------------------------------------------------------------------
# GNU C++ only.

$<$<COMPILE_LANGUAGE:CXX>:-Wcomma-subscript>
$<$<COMPILE_LANGUAGE:CXX>:-Wredundant-tags>
$<$<COMPILE_LANGUAGE:CXX>:-Wvolatile>
)

# RISC-V 10.1 fails with `note: replace the class-key with 'struct'`.
if(NOT "${CMAKE_C_COMPILER_VERSION}" VERSION_EQUAL "10.1.0")

list(APPEND ${variable_name}

$<$<COMPILE_LANGUAGE:CXX>:-Wmismatched-tags>
)

endif()

endif()

elseif("${CMAKE_C_COMPILER_ID}" MATCHES ".*Clang")

message(VERBOSE "Adding clang warnings...")

list(APPEND ${variable_name}

# For clang things are much easier.
-Weverything
$<$<C_COMPILER_ID:ARMClang>:-Wno-poison-system-directories>
)

endif()
```
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.