MISRA Discussion Forums
Rule R7.0.1 converting constructor question - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188)
+---- Forum: 4.7 Standard conversions (https://forum.misra.org.uk/forumdisplay.php?fid=193)
+---- Thread: Rule R7.0.1 converting constructor question (/showthread.php?tid=1700)



Rule R7.0.1 converting constructor question - gdavis - 22-08-2024

Hello,

Rule 7.0.1 allows for an explicit cast from bool to T when T has a converting constructor with a parameter of type bool. The example for the rule shows:

struct A
{
  explicit A ( bool );
};

A anA { true };       // Compliant - constructor

Yet, C++ requires a converting constructor to be non-explicit.

I'm not sure what the intent is, but perhaps the rule should allow for an explicit cast from B to T when T has an explicit constructor that takes a single parameter, a parameter of (possibly const-qualified) type bool.

Please advise. Thank you.


RE: Rule R7.0.1 converting constructor question - misra cpp - 02-09-2024

You're right, we should not have used the phrase 'converting constructor' in the rule.

We should have said, 'a constructor taking a single parameter of type bool (possible qualified)'

This will be corrected in the next release