MISRA Discussion Forums
Rule M7-3-4 and UDLs - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: AUTOSAR C++:2014 rules (https://forum.misra.org.uk/forumdisplay.php?fid=185)
+--- Thread: Rule M7-3-4 and UDLs (/showthread.php?tid=1608)



Rule M7-3-4 and UDLs - davebrown - 18-03-2022

When using UDLs like the ones provided by std::chrono, for example, we get a violation of rule M7-3-4 when including the UDL namespace:

Code:
using namespace std::chrono_literals; // <- violation here

Naturally, this rule was written before UDLs were a thing and so it's inevitably not designed for this use case.

We have discussed two options for this:
  1. Partially deviate for this use case only
  2. Explicitly import the required UDL(s)
The first option is probably okay if we can limit the scope sufficiently but someone has to write it and defend it.
The second option requires writing code similar to:
Code:
using std::chrono_literals::operator""s;
using std::chrono_literals::operator""ms;
which is a little cumbersome, especially for developers unfamiliar with how a UDL is written.

What I would like to know is how MISRA intends to handle UDLs in the upcoming guidelines? If they are allowed, how should they be imported for convenient use? Will M7-3-4 be updated to include an exception for namespaces that define UDLs?

Thank you in advance for you time.

/Dave


RE: Rule M7-3-4 and UDLs - misra cpp - 22-03-2022

For the next version of MISRA C++, we are currently planning to allow  using-directives within any namespace, other than the global namespace.


RE: Rule M7-3-4 and UDLs - davebrown - 29-03-2022

Thank you for the clarification.


RE: Rule M7-3-4 and UDLs - misra cpp - 29-04-2022

This thread is now closed

For any related questions, please open a new thread