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 via email to