Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 7.0.2: Why the requirement for 'explicit' conversion operator?
#1
Rule 7.0.2 has exceptions for "a class type having an explicit operator bool."

Question: why does the conversion operator have to be 'explicit' for the exception to apply? Even if the conversion operator is implicit, clearly the class was designed to be convertible to bool. This requirement seems therefore excessive.

I'm thinking for example about std::bitset::operator[] which returns a proxy object convertible to bool. However since the conversion operator is not explicit (as specified in the C++ standard), then even performing an explicit cast to bool from the proxy object violates Rule 7.0.2. 

Note: I am aware that the 'const' version of std::bitset::operator[] should return a 'bool' directly, but some implementations return the proxy object also here, so the conversion is still necessary.
Reply
#2
We are in the process of publishing an erratum to MISRA C++:2023, in that the word 'explicit' has been removed from 7.0.2

Publication is imminent
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#3
Great to hear, thank you for the update!
Reply
#4
Thread now closed - please post any follow-up as a new thread
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)