Bug 60135 - add option to warn if ctor/conversion declared implicit
Summary: add option to warn if ctor/conversion declared implicit
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2014-02-10 16:29 UTC by Matthew Woehlke
Modified: 2021-03-28 07:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Woehlke 2014-02-10 16:29:34 UTC
"explicit" is a great tool for avoiding mistakes in the use of a class. Unfortunately, programmers must remember to use it, and there is not presently a mechanism to diagnose failure to do so.

I would like to request that g++ add (1) a warning if a constructor or conversion operator is not declared "explicit", and (2) some mechanism (e.g. an attribute) to silence this warning for a particular declaration, i.e. to annotate that a constructor or conversion operator is intended to be implicit. This would help to prevent forgetting to make such "explicit" when implicit behavior is not desired.
Comment 1 Eric Gallager 2017-08-25 14:23:20 UTC
Confirming as an enhancement. Call it "-Wsuggest-explicit" perhaps?