public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "felix.von.s at posteo dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/106940] New: Feature request: -Wsuggest-noexcept and -Wsuggest-explicit
Date: Wed, 14 Sep 2022 08:56:14 +0000	[thread overview]
Message-ID: <bug-106940-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106940

            Bug ID: 106940
           Summary: Feature request: -Wsuggest-noexcept and
                    -Wsuggest-explicit
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.von.s at posteo dot de
  Target Milestone: ---

When writing classes, I routinely tend to forget that constructors can be used
for implicit conversions, unless marked explicit.

I also tend to forget about noexcept specifiers, which can lead to performance
pitfalls, especially with move constructors and move assignment operators.

So I would like a compiler warning that could remind me to consider such
concerns.  In case of noexcept, I don’t particularly need full semantic
analysis of the body; a pure syntax check whether the specifier is present
should suffice.  And in case of explicit, no other kind of check is possible,
obviously.

I imagine -Wsuggest-explicit could be suppressed for copy and move constructors
from the same type.  I am undecided whether it should apply to conversion
operators, but leaning towards yes.

The warnings would be silenced by adding explicit specifiers: explicit(false)
and noexcept(false).  Each warning should probably require the earliest
language version where the respective silencing is possible (C++20 and C++11,
respectively).

             reply	other threads:[~2022-09-14  8:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-14  8:56 felix.von.s at posteo dot de [this message]
2022-09-14  9:19 ` [Bug c++/106940] " redi at gcc dot gnu.org

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=bug-106940-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).