Menu

cppcheck and Boost

2021-10-04
2021-10-06
  • david ingamells

    david ingamells - 2021-10-04

    Hi, I an trying to get version 2.5 working with our codebase, but am encountering a problem when using Boost include files. I am giving cppcheck a compilecommands.json cmake project file which for the file with a problem specifies the boost include directory as an '-isystem' path.
    The file with a problem begins with these first 54 lines:

    #ifndef MSGENERALPP_REFLECTIVE_STRUCT
    #define MSGENERALPP_REFLECTIVE_STRUCT
    
    #include <MSGeneralpp/ReferenceTuple.h>
    #include <boost/algorithm/string/join.hpp>
    #include <boost/format.hpp>
    #include <boost/preprocessor/seq/for_each.hpp>
    #include <boost/preprocessor/seq/transform.hpp>
    #include <boost/preprocessor/seq/enum.hpp>
    #include <boost/preprocessor/tuple/elem.hpp>
    #include <boost/preprocessor/tuple/size.hpp>
    #include <boost/preprocessor/tuple/eat.hpp>
    #include <boost/preprocessor/variadic/to_list.hpp>
    #include <boost/preprocessor/list/for_each.hpp>
    #include <boost/preprocessor/control/if.hpp>
    #include <boost/preprocessor/comparison/greater.hpp>
    #include <boost/preprocessor/punctuation/remove_parens.hpp>
    #include <boost/tti/has_type.hpp>
    
    #include <cstddef>
    #include <utility>
    #include <vector>
    
    ...
    
    // Create a meta function "has_type_IAmReflective" that tells us whether a type
    // has an embedded declaration of a type called "IAmReflective".
    BOOST_TTI_HAS_TYPE( IAmReflective)
    

    cppcheck always reports the following error for that last line:

            <error file0="<path>/src/Geo/uniqueGaiaGeomCollPtr.cpp" id="unknownMacro" msg="There is an unknown macro here somewhere. Configuration is required. If BOOST_TTI_HAS_TYPE is a macro then please configure it." severity="error" verbose="There is an unknown macro here somewhere. Configuration is required. If BOOST_TTI_HAS_TYPE is a macro then please configure it.">
                <location column="1" file="<path>/src/ReflectiveStruct.h" info="" line="54"/>
            </error>
    

    The cppcheck command used was

    cppcheck --xml -D__cppcheck__ -inline-suppr --std=c++20  --project=compile_commands.json
    

    Given that I am tying to set thing up so that the same framework can be used for about 50 code bases, does anybody here have any suggestions about how to proceed? The code compiles and is in heavy use, as well as being written by an expert C++ developer.

     
  • david ingamells

    david ingamells - 2021-10-04

    My desktop started behaving weird, so missed adding a thanks in advance to this

     
  • CHR

    CHR - 2021-10-04

    Normally, you would run cppcheck with --library=boost. However, BOOST_TTI_HAS_TYPE is not part of boost.cfg. You could try and add this line

      <define name="BOOST_TTI_HAS_TYPE(x)" value=""/>
    
     
    👍
    1
    • Daniel Marjamäki

      I agree with CHR. Please use --library=boost.

      If you do not want to edit boost.cfg now you could also edit the command line:

      danielm@debian:~/cppcheck$ ./cppcheck 1.cpp
      Checking 1.cpp ...
      1.cpp:24:1: error: There is an unknown macro here somewhere. Configuration is required. If BOOST_TTI_HAS_TYPE is a macro then please configure it. [unknownMacro]
      BOOST_TTI_HAS_TYPE( IAmReflective)
      ^
      danielm@debian:~/cppcheck$ ./cppcheck "-DBOOST_TTI_HAS_TYPE(x)=" 1.cpp
      Checking 1.cpp ...
      Checking 1.cpp: BOOST_TTI_HAS_TYPE(x)=...
      danielm@debian:~/cppcheck$ 
      

      We should configure the BOOST_TTI_HAS_TYPE in boost.cfg for the next cppcheck release. cppcheck-2.7.

       
  • david ingamells

    david ingamells - 2021-10-05

    Thanks for the support. I will try that. One think that puzzles me is that I am giving the include path to the Boost include files via the cmake project file, so why doesn't cppcheck use the defines in those?

     
  • david ingamells

    david ingamells - 2021-10-06

    Daniel, MHR,
    I can confirm that your suggestion worked. In addition, so far I have found 2 other boost macros that our code uses so the total that needed adding is:

    <define name="BOOST_PP_SEQ_FOR_EACH(macro, data, list)" value=""/>
    <define name="BOOST_PP_SEQ_TRANSFORM(macro, data, list)" value=""/>
    <define name="BOOST_TTI_HAS_TYPE(x)" value=""/>
    
     

    Last edit: david ingamells 2021-10-06
  • CHR

    CHR - 2021-10-06

    Thanks, I have added them here: https://github.com/danmar/cppcheck/pull/3487

     

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.