Menu

[preprocessorErrorDirective] #if __has_include

2022-02-25
2022-04-20
  • Christian Eggers

    Version: 2.7

    I have problems with the C++17 __has_include() preprocessor statement:
    https://en.cppreference.com/w/cpp/preprocessor/include

    This statement appears in some gcc-11 system headers and in some own files.

    It looks like cppcheck performs no further scanning if the __has_include()
    statement appears in an included file.

    Example code:

    Foo.hpp
    --------------------------------8<--------------------------------

    ifndef FOO_HPP_

    define FOO_HPP_

    if __has_include()

    include

    endif

    class Foo
    {
    public:
    Foo();
    ~Foo() = default;
    Foo(const Foo &other) = delete;
    Foo(Foo &&other) = delete;
    Foo& operator=(const Foo &other) = delete;
    Foo& operator=(Foo &&other) = delete;
    };

    endif / FOO_HPP_ /

    -------------------------------->8--------------------------------

    Foo.cpp
    --------------------------------8<--------------------------------

    include "Foo.hpp"

    Foo::Foo()
    {

    }

    -------------------------------->8--------------------------------

    cppcheck Foo.cpp

    Checking Foo.cpp ...
    Foo.hpp:11:0: error: failed to evaluate #if condition [preprocessorErrorDirective]

    if __has_include()

    ^

    regards
    Christian


    Christian
    Eggers
    Software Engineer

    ARRI
    Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
    Arriweg 17,
    83071
    Stephanskirchen
    www.arri.com

    +49 8036 3009-3118
    CEggers@arri.de


    Get all the latest information from www.arri.com, Facebook, Twitter, Instagram and YouTube.

    Arnold & Richter Cine Technik GmbH & Co. Betriebs KG
    Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRA 57918
    Persönlich haftender Gesellschafter: Arnold & Richter Cine Technik GmbH
    Sitz: München - Registergericht: Amtsgericht München - Handelsregisternummer: HRB 54477
    Geschäftsführer: Dr. Michael Neuhäuser; Stephan Schenk; Walter Trauninger; Markus Zeiler

     
  • Bill Torpey

    Bill Torpey - 2022-04-20

    Similar issue with boost (include/boost/config/detail/select_stdlib_config.hpp):

    #if defined(__cplusplus) && defined(__has_include)
    #  if __has_include(<version>)
    // It should be safe to include `<version>` when it is present without checking
    ...
    
     

Log in to post a comment.