MISRA Discussion Forums
Use of constexpr - 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++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.1 General (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=130)
+---- Thread: Use of constexpr (/showthread.php?tid=1329)



Use of constexpr - mikearmagedon - 31-03-2017

I am working on an embedded system project and using constexpr on the following situations:
- on constructors so that objects can be statically initialized in compile time
- on functions that are used to initialize constant values
- on constant variables, as an alternative to constant macros (as it violates rule 16-2-2)

The main reasons for using constexpr are (a)to avoid dynamic initialization, making the system more secure, and (b)to make better use of the system's ROM memory.

The constexpr is a language extension so a deviation procedure is necessary to allow its usage.

I would like to know first, if there is any way of achieving the same without the need to write a deviation procedure?

If such is not possible, are the reasons above enough to justify a deviation procedure?

Kind regards,
Miguel Araújo


Re: Use of constexpr - misra cpp - 10-07-2017

MISRA C++:2008 is based on C++:2003, which does not include constexpr

When MISRA C++ is revised it will be based on a more recent version of the C++ standard, and will consider the use of constexpr