Skip to content

Preprocessor allows for name collision with directory like 'exception' #2692

@baemhai

Description

@baemhai

Before you create a new issue

  • Is it really a cxx-plugin issue ... yes
  • Please read the [Wiki] ... check: relevant pages are on includeDirectories, troubleshooting, detect and fix, jsonCompilationDatabase
  • Please [turn debug info on] ... check
  • Please check if there is not already a [bug report] ... check

Describe the bug

  • A source file includes <exception>.
  • A include folder named exception exists along the search list:
    • e.g. include/exception/MyException.hpp
    • class MyException typically also includes <exception>, which may account for some occurrences of the error if the header is in cxx.sources
  • Sonar finds the folder, instead of e.g. /usr/include/c++/11/exception .
    • error message is like ERROR preprocessor: .../include/exception (Is a directory) ...
  • This screenshot shows grepping over 4 sonar-scanner logs grep -Hne 'Is a directory' 202* Screenshot_from_2024-06-08_08-09-00
    1. The first run (20240608-073726) has both sonar.cxx.jsonCompilationDatabase=build/compile_commands.json and sonar.cxx.includeDirectories=include configured. The log shows the error two times.
    2. The second run (20240608-075350) has both lines commented out, eliminating the error. This is not a workaround for any real-world project. It demonstrates that <exception> is found just like the compiler does it.
    3. The third run re-introduces the problem with compilation database only, producing one error
    4. The third run re-introduces the problem with cxx.includeDirectories only, producing two errors

To Reproduce
Steps to reproduce the behavior:

  1. See the small example attached example.tar.gz

Expected behavior
Since the compiler is able to work it out, cxx's preprocessor should too: a directory should not match when looking for a header file.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • SonarQube version: 9.9.5
  • cxx plugin version: 2.1.1.488
  • sonar-scanner version: 6.0.0.4432

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions