platformio / platformio-core

Your Gateway to Embedded Software Development Excellence :alien:
https://platformio.org
Apache License 2.0
7.83k stars 789 forks source link

cppcheck doesn't seem to be able to handle __has_include() properly #4688

Closed ssilverman closed 1 year ago

ssilverman commented 1 year ago

What kind of issue is this?

Configuration

Operating system: macOS 13.4.1

PlatformIO Version (platformio --version): 6.1.9

Building for a Teensy 4.1 and C++17. Added this line to platformio.ini:

build_unflags = -std=gnu++14 -std=c++14

Description of problem

cppcheck doesn't seem to be able to handle __has_include() properly. Is it possible it's just not working with angle-bracket includes?

Steps to Reproduce

  1. Run "Inspect" tool on any C++17 project.

Actual Results

"failed to evaluate #if condition" errors that look like this:

Error: Found a breaking defect 'failed to evaluate #if condition' in ~/.platformio/packages/toolchain-gccarmnoneeabi-teensy/arm-none-eabi/include/c++/11.3.1/arm-none-eabi/bits/c++config.h:759

Code at line 759:

#if __has_include(<pstl/pstl_config.h>)

When I comment that out, it fails in other places. For example, line 37 in ~/.platformio/packages/toolchain-gccarmnoneeabi-teensy/arm-none-eabi/include/c++/11.3.1/ext/atomicity.h:

#if __has_include(<sys/single_threaded.h>)

Expected Results

No "failed to evaluate #if condition" errors.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env]
build_flags = -Wall -g -Og -fno-single-precision-constant
build_unflags = -std=gnu++14 -std=c++14
monitor_speed = 115200

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino

Source file to reproduce issue:: N/A

Additional info

ssilverman commented 1 year ago

I wasn't sure if this is the correct spot, or if this issue needs to be in platformio-vscode-ide.

valeros commented 1 year ago

Hi @ssilverman, indeed Cppcheck's internal parser is quite limited and can fail to evaluate tricky code in some custom embedded packages. That's why we have the check_skip_packages option for such cases.