[
https://issues.apache.org/jira/browse/MESOS-1055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13920276#comment-13920276
]
Bernd Mathiske commented on MESOS-1055:
---------------------------------------
I am wondering whether one can check for potentially bad implicit conversions
with a compiler option - rather than looking at all existing single parameter
constructors and then deciding whether or not to put "explicit" before them.
Maybe "-Weffc++"? But that produces way too many other warning messages, so it
cannot stay switched on all the time.
Maybe use a tool to programmatically find all single parameter constructors and
insert "explicit" everywhere, then manually refit the hopefully only few places
where type check errors occur. What tool does that?
In any case, it would be good practice to always write "explicit" by default
from now on, I suppose.
> Add explicit to single argument constructors
> --------------------------------------------
>
> Key: MESOS-1055
> URL: https://issues.apache.org/jira/browse/MESOS-1055
> Project: Mesos
> Issue Type: Improvement
> Components: c++ api
> Reporter: Dominic Hamon
> Priority: Minor
> Labels: c++, newbie
>
> From the google style guide:
> Normally, if a constructor takes one argument, it can be used as a
> conversion. For instance, if you define Foo::Foo(string name) and then pass a
> string to a function that expects a Foo, the constructor will be called to
> convert the string into a Foo and will pass the Foo to your function for you.
> This can be convenient but is also a source of trouble when things get
> converted and new objects created without you meaning them to. Declaring a
> constructor explicit prevents it from being invoked implicitly as a
> conversion.
> Implicit conversions should be the exception to avoid unwanted and unexpected
> behaviour.
--
This message was sent by Atlassian JIRA
(v6.2#6252)