Menu

Does cppcheck not complain about new features

2019-01-17
2019-01-18
  • Kevin Moloney

    Kevin Moloney - 2019-01-17

    I was expecting to see failures when using c++11 features such as auto/nullptr etc and building with flag std-c++03. However cppcheck doesn't complain. Is this expected behavior?

     
  • Mr. X

    Mr. X - 2019-01-17

    This is expected behaviour. Cppcheck is not a syntax validator.

     
  • Kevin Moloney

    Kevin Moloney - 2019-01-17

    Oh ok so it expects that the code is valid. I would have thought if it didn't understand the syntax it would throw up some sort of error though.

     
  • versat

    versat - 2019-01-18

    From the Cppcheck manual:

    Chapter 1. Introduction
    Cppcheck is an analysis tool for C/C++ code. Unlike C/C++ compilers and many other analysis tools, it doesn't detect syntax errors. Instead, Cppcheck detects the types of bugs that the compilers normally fail to detect. The goal is no false positives.

    This does not mean that Cppcheck accepts all garbage :) There is a syntaxError message that is issued when Cppcheck really can not go on analyzing the source code because it really looks invalid to Cppcheck and does not make sense at all.

    I am not sure what happens when you set the standard to C++03 for Cppcheck analysis but use nullptr. Maybe Cppcheck just handles nullptr correctly as if this part of the source code is C++11 code.

    Generally the source code should be compilable and the more information you give to Cppcheck (defines, libraries, project include directories, ...) the better should be the result.

     

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.