MISRA Discussion Forums

Full Version: Rule M7-3-4 and UDLs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
For the next version of MISRA C++, we are currently planning to allow  using-directives within any namespace, other than the global namespace.
Thank you for the clarification.
This thread is now closed

For any related questions, please open a new thread