public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Liviu Ionescu <ilg@livius.net>
To: newlib@sourceware.org
Subject: Re: -Wall
Date: Sun, 21 Jan 2024 13:41:13 +0200	[thread overview]
Message-ID: <273C14D6-0D9D-4E8D-BF08-F9E99BFACC43@livius.net> (raw)
In-Reply-To: <ZapxLOLazU-oWKIS@calimero.vinschen.de>



> On 19 Jan 2024, at 14:55, Corinna Vinschen <vinschen@redhat.com> 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()
```


      parent reply	other threads:[~2024-01-21 11:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 12:55 -Wall Corinna Vinschen
2024-01-19 15:38 ` -Wall Mike Frysinger
2024-01-19 15:55   ` -Wall Joel Sherrill
2024-01-19 16:23 ` -Wall Liviu Ionescu
2024-01-19 18:34   ` -Wall Liviu Ionescu
2024-01-20 18:17 ` -Wall brian.inglis
2024-01-24  5:38   ` -Wall brian.inglis
2024-01-24 11:19     ` -Wall Corinna Vinschen
2024-01-24 11:25       ` -Wall Liviu Ionescu
2024-01-24 13:06         ` -Wall Corinna Vinschen
2024-01-21 11:41 ` Liviu Ionescu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=273C14D6-0D9D-4E8D-BF08-F9E99BFACC43@livius.net \
    --to=ilg@livius.net \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).