-
Notifications
You must be signed in to change notification settings - Fork 362
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
Question: Reproduce parsing errors on local machine #2286
Comments
Hi @amai2012, you found already https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Detect-and-fix-parsing-errors. The best way is normally to define some macros to fix parsing errors. You should always keep in mind, that the cxx parser is only doing a syntax analysis (you don't have to provide all includes, macros, types for a semantic analysis): Add the macros of your project to a header file and include it with https://github.com/SonarOpenCommunity/sonar-cxx/wiki/sonar.cxx.forceIncludes. Good samples for headers are here: https://github.com/SonarOpenCommunity/sonar-cxx/tree/master/cxx-sensors/src/main/resources/macros. To test things locally on your PC you can use the SSLR toolkit. Copy paste your code into the toolkit window
Hope this helps! Regards, |
So far I have found three kind of issues:
And this one: struct Portfolio { int get() const; };
int check(const Portfolio& parObj, const int ind)
{
if (parObj.get() < 0 || parObj.get() >= ind)
{
return 0;
}
return 1;
} triggers
|
Hello @amai2012, thank you for your investigation. Could you please further narrow down the last finding. Try each test individual with the SSLR toolkit. Maybe it’s the // Test 1
struct Portfolio { int get() const; };
int check(const Portfolio& parObj, const int ind) { return 1; }
// Test 2
int check(const Portfolio& parObj, const int ind) { return 1; }
// Test 3
int check(const int ind) { return 1; }
// Test 4
int check(int ind) { return 1; } Regards, |
Tests 1-4 are passing here, the original example fails. struct Portfolio { int get() const; };
void check( Portfolio& parObj, int ind)
{
if (parObj.get() < 0 || parObj.get() >= ind)
{
return;
}
} I observe some odd behaviour with that sslr-tool here: |
Hi @amai2012, I was able to narrow this down (see below). Problem are the brackets That has maybe something to do with sonar-cxx/cxx-squid/src/main/java/org/sonar/cxx/channels/RightAngleBracketsChannel.java Line 44 in fa5575c
sonar-cxx/cxx-squid/src/main/java/org/sonar/cxx/channels/RightAngleBracketsChannel.java Line 57 in fa5575c
Samples: void check() { // failure
a() < 0 || c >= 1;
}
void check() { // ok
a() < 0 || c > 1;
}
void check() { // ok
a < 0 || c >= 1;
}
//-------------------------------------------------
void check() { // failure
if ( a.b() < 0 || c >= 1) {}
}
void check() { // failure
if ( a() < 0 || c >= 1) {}
}
void check() { // failure
if ( a.b(1) < 0 || c >= 1 ) {}
}
void check() { // ok
if ( a() < 0 || c > 1) {}
}
void check() { // ok
if ( (a.b() < 0) || (c >= 1) ) {}
}
void check() { // ok
if ( a.b < 0 || c >= 1) {}
}
void check() { // ok
if ( a < 0 || c >= 1) {}
} |
- close SonarOpenCommunity#2286 ```C++ void check() { a() < 0 || c >= 1; } ```
- close SonarOpenCommunity#2286 ```C++ void check() { a() < 0 || c >= 1; } ```
- close SonarOpenCommunity#2286 ```C++ void check() { a() < 0 || c >= 1; } ```
- close SonarOpenCommunity#2286 ```C++ void check() { a() < 0 || c >= 1; a() < 0 || c > 1; a() < 0 || c >> 1; if(a() < 0 || c >= 1) {} if(a() < 0 || c > 1) {} if(a() < 0 || c >> 1) {} Y<X<(6<1)>>; Y<X<(6>=1)>>; Y<X<(6<=1)>>; Y<X<(6>>1)>>; Y<X<(6<<1)>>; Y<X<(6<=>1)>>; } ```
Thanks for fixing this. |
I have a lot of parsing errors in my codebase.
https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Detect-and-fix-parsing-errors has some suggestions but I lack a short hello-world project for testing.
Is it possible to reproduce the parse errors on my local machine without a full-blown analysis?
The text was updated successfully, but these errors were encountered: