Menu

C++17 support in Cppcheck

There has been questions before about how well Cppcheck handles the latest C++ standard language features. And unfortunately I feel I could not answer that very well.

Lately I have been investigating C++20 (and below) support. Cppcheck-2.4.1 has pretty good support overall for C++17 (and lower) and it also handle a few C++20 features. We have improved the parser and I now feel that latest Cppcheck development build support all C++17 language features and a couple of additional C++20 features. The improved parser will be available in Cppcheck-2.5.

The builtin Cppcheck parser is designed to handle incomplete code and code with various compiler extensions. As a consequence it is not very strict. Therefore the checks do not have very strict requirements neither.
In my investigation I wanted to ensure that Cppcheck parser meets the requirements of the checks so you will catch bugs and avoid false positives.

Here is a table with my notes for C++17 language features:

Making the text message for static_assert optional            Yes
Allow typename in a template template parameter               Yes
New rules for auto deduction from braced-init-list            Yes
Nested namespace definitions                                  Yes
Attributes for namespaces and enumerators                     Yes
attribute [[fallthrough]]                                     Yes
attribute [[nodiscard]]                                       Yes
attribute [[maybe_unused]]                                    Yes
UTF-8 character literals                                      Yes
Hexadecimal floating-point literals                           Yes
Use of auto as the type for a non-type template parameter     Yes
Constant evaluation for all non-type template arguments       Yes (template is not instantiated)
Fold expressions, for variadic templates                      Yes (fold expressions are replaced by function call)
if constexpr                                                  Yes
Structured binding declarations                               Yes
Initializers in if and switch                                 Yes
copy-initialization and direct initialization (copy-elision)  Yes, not optimised
Some extensions on over-aligned memory allocation             Yes
Class template argument deduction                             Yes (template is not instantiated)
Inline variables                                              Yes
__has_include                                                 Yes
Value of __cplusplus changed to 201703L                       Yes
Exception specifications were made part of the function type  Yes, not strict
Direct list initialization of enums                           Yes
constexpr lambda                                              Yes
Lambda capture this by value                                  Yes

The C++20 support is work in progress, and will hopefully be ready soon.

Posted by Daniel Marjamäki 2021-04-26

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.