isocpp / isocpp/CppCoreGuidelines
No mention of implicit conversion of a constructor with default arguments in C.46
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
I think this section "C.46: By default, declare single-argument constructors explicit" could be improved if there would be a Note saying that a constructor with default arguments acts like a single-argument constructor. For instance, the following constructor (without explicit) does not avoid implicit conversion, even though it is not a single-argument constructor (?), but rather acts like the one (both parameters have defaults or only the 2nd one -- it doesn't matter):
struct Foo {
/*explicit*/ Foo(int a = 0, int b = 0) : sum{a + b} { }
int sum;
};
void bar() {
Foo foo = 10; // implicit conversion
}
(?) I mean, I'm not sure, maybe Foo::Foo(int, int) shown above is a book-case example of "single-argument constructor", but I think it's worth mentioning that one should not only be aware of Foo::Foo(int a) case, but Foo::Foo(int a/*,=0*/, int b = 0/*, int c = 0, and so on */) as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the C.46 section in the C++ Core Guidelines, especially its discussion of single-argument constructors. Add a note covering constructors with default arguments and the implicit conversion shown in the issue. Done means the guidance clearly warns readers about this case without changing the surrounding rule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100