C++: Make constructor-used-as-copy-constructor warning/low

This query is supposed to look for constructors that unintentionally qualify as copy constructors due to default arguments. There are quite a few real-world projects that define such constructors intentionally. I've reduced the severity to "warning" and the precision to "low" due to the high false positive rate.
This commit is contained in:
Dave Bartolomeo
2019-05-29 17:46:24 -07:00
parent a782585d74
commit e90403be31
2 changed files with 3 additions and 4 deletions

View File

@@ -11,8 +11,7 @@ when their default arguments are taken into account. An example would be a const
of the form <code>X(const X&amp; rhs, int i = 0)</code>. A compiler will use such a constructor as a copy
constructor in preference to the default member-wise copy constructor that it would otherwise generate.
Since this is usually not what was intended, constructors of the form often do not provide the right
semantics for copying objects of the class, making them potentially dangerous. Even when this sort of
thing has been done intentionally, it is confusing and in bad taste, and should be avoided.
semantics for copying objects of the class, making them potentially dangerous.
</p>
</overview>

View File

@@ -2,8 +2,8 @@
* @name Constructor with default arguments will be used as a copy constructor
* @description Constructors with default arguments should not be signature-compatible with a copy constructor when their default arguments are taken into account.
* @kind problem
* @problem.severity error
* @precision high
* @problem.severity warning
* @precision low
* @id cpp/constructor-used-as-copy-constructor
* @tags reliability
* readability