Bug 60135

Summary: add option to warn if ctor/conversion declared implicit
Product: gcc Reporter: Matthew Woehlke <mw_triad>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: egallager, webrown.cpp
Priority: P3 Keywords: diagnostic
Version: unknown   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63458
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2017-08-25 00:00:00
Bug Depends on:    
Bug Blocks: 87403    

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?