简体   繁体   中英

Does libstdc++ comply with MISRA C++?

This is motivated by a question that I made previously (on the same topic):

Do BLAS and LAPACK libraries comply with MISRA standard?

Now I have a much more important question: is libstdc++ (which is the implementation of the standard library by gcc) MISRA C++:2008 compliant? I assume the answer is yes ... as long as you compile your code with gcc and the -std=c++03 flag.

What happens if I compile the code with the standard from 2011 (ie -std=c++11 )? Is that MISRA C++:2008 compliant? Do I have to prove that the libstdc++ is MISRA compliant? I can write deviations for a couple of rules (for example, I want to use std::array instead of C-style arrays), but writing them for the whole MISRA standard looks like a terryfying task.

I would appreciate any insight into this topic.

No, it is not MISRA-C++ compliant. Neither is glibc. But then there's no requirement from the standard that the library must be written in a certain language either. Standard compliance for the standard library itself is a rather muddy topic, with or without MISRA.

I very much doubt that MISRA-C++ is a priority for these libraries. The library (and gcc) maintainers are mostly from the Linux/Desktop ("hosted system") side of things, where MISRA compliance isn't required.

If you need a MISRA compliant standard library, you'll have to look at the various commercial embedded systems compilers.

What happens if I compile the code with the standard from 2011? Is that MISRA C++:2008 compliant?

No it is not compliant. MISRA-C++ requires explicitly that you use C++03, so it will be very hard to justify a deviation here.

Do I have to prove that the libstdc++ is MISRA compliant?

There is no way to prove it, since it is not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM