Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
baemhai opened this issue Jun 8, 2024 · 3 comments · Fixed by #2726
Closed

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

baemhai opened this issue Jun 8, 2024 · 3 comments · Fixed by #2726
Assignees
Labels
Milestone

Comments

@baemhai
Copy link

baemhai commented Jun 8, 2024

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
@guwirth guwirth added the bug label Jul 3, 2024
@guwirth
Copy link
Collaborator

guwirth commented Jul 3, 2024

Hi @baemhai, thx for your feedback, we will have a look to it …

@guwirth
Copy link
Collaborator

guwirth commented Aug 27, 2024

relevant LOG file items:

07:37:26.643 INFO  Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
07:37:26.646 INFO  Project root configuration file: /home/vagrant/Desktop/mini.git/sonar-project.properties
07:37:27.381 DEBUG Work directory: /home/vagrant/Desktop/mini.git/.scannerwork
07:37:35.480 INFO  Project key: mini
07:37:35.481 INFO  Base dir: /home/vagrant/Desktop/mini.git
07:37:35.481 INFO  Working dir: /home/vagrant/Desktop/mini.git/.scannerwork
07:37:35.734 DEBUG Creating module hierarchy
07:37:35.735 DEBUG   Init module 'mini'
07:37:35.735 DEBUG     Base dir: /home/vagrant/Desktop/mini.git
07:37:35.735 DEBUG     Working dir: /home/vagrant/Desktop/mini.git/.scannerwork
07:37:35.735 DEBUG     Module global encoding: UTF-8, default locale: en_US
...
07:37:44.272 INFO  Indexing files...
07:37:44.398 DEBUG 46 non excluded files in this Git repository
07:37:44.407 DEBUG 'src/mini.cpp' indexed with language 'cxx'
07:37:44.411 DEBUG 'include/exception/secondlevel.hpp' indexed with language 'cxx'
07:37:44.411 DEBUG 'include/mini.hpp' indexed with language 'cxx'
07:37:44.413 DEBUG 'include/firstlevel.hpp' indexed with language 'cxx'
07:37:44.415 INFO  4 files indexed
07:37:44.415 INFO  0 files ignored because of scm ignore settings
...
07:37:46.296 INFO  Sensor CXX [cxx]
07:37:46.329 DEBUG Parsing 'JSON Compilation Database' format
07:37:46.533 DEBUG global include directories: [/home/vagrant/Desktop/mini.git/include]
07:37:46.534 DEBUG global macros: [{__STDC__:1}, {__has_c_attribute(x):0}, {__has_extension(x):0}, {__has_cpp_attribute(x):0}, {__STDC_HOSTED__:1}, {__has_builtin(x):0}, {__FILE__:"file"}, {__has_feature(x):0}, {__DATE__:"??? ?? ????"}, {__has_warning(x):0}, {__LINE__:1}, {__is_identifier(x):1}, {__TIME__:"??:??:??"}, {__has_include_next:__has_include_next}, {__has_declspec_attribute(x):0}, {__has_include:__has_include}, {__cplusplus:201402L}, {__has_attribute(x):0}]
...
07:37:46.535 DEBUG process unit '/home/vagrant/Desktop/mini.git/include/exception/secondlevel.hpp'
07:37:46.541 DEBUG process include file '/home/vagrant/Desktop/mini.git/include/exception'
07:37:46.543 ERROR preprocessor: /home/vagrant/Desktop/mini.git/include/exception (Is a directory) '/home/vagrant/Desktop/mini.git/include/exception'
...
07:37:47.727 WARN  Preprocessor: 3 include directive error(s). This is only relevant if parser creates syntax errors. The preprocessor searches for include files in the with 'sonar.cxx.includeDirectories' defined directories and order.
07:37:47.739 INFO  Analysis total time: 12.700 s
07:37:47.740 INFO  EXECUTION SUCCESS
07:37:47.741 INFO  Total time: 21.099s

File /home/vagrant/Desktop/mini.git/include/exception/secondlevel.hpp

#include <exception>
class Exception : public std::exception {};

process include file:

public void handleFile(AstNode ast, Token token) {

line with error message:
ERROR preprocessor: /home/vagrant/Desktop/mini.git/include/exception (Is a directory) '/home/vagrant/Desktop/mini.git/include/exception'

LOG.error(LOGMSG, e.getMessage(), fileName);

@guwirth
Copy link
Collaborator

guwirth commented Aug 27, 2024

Hello @baemhai,

you can try with (#2726) https://github.com/SonarOpenCommunity/sonar-cxx/actions/runs/10579102991/artifacts/1859720937 if the problem is solved.

Regards,

@guwirth guwirth added this to the 2.1.3 milestone Aug 27, 2024
@guwirth guwirth self-assigned this Aug 27, 2024
@SonarOpenCommunity SonarOpenCommunity locked as resolved and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

2 participants