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

clang-tidy: Support diagnostic notes #1720

Closed
jspam opened this issue May 13, 2019 · 2 comments · Fixed by #1742
Closed

clang-tidy: Support diagnostic notes #1720

jspam opened this issue May 13, 2019 · 2 comments · Fixed by #1742
Assignees
Milestone

Comments

@jspam
Copy link

jspam commented May 13, 2019

clang-tidy often provides additional context for its diagnostic in the form of notes. These are currently lost when parsing a clang-tidy log file.

SonarQube supports issue flows, which seem like the appropriate way to display that information. See https://docs.sonarqube.org/display/SONARQUBE67/Issues , section "Understanding issue context"

Example 1:

#include <cstdio>
  
int X;

int main(int argc, char** argv)
{
    int* x = nullptr;
    if (argc > 1) {
        x = &X;
    }
    printf("%d", *x);
}

clang-tidy output:

1 warning generated.
/tmp/static-analyzer.cpp:11:18: warning: Dereference of null pointer (loaded from variable 'x') [clang-analyzer-core.NullDereference]
    printf("%d", *x);
                 ^
/tmp/static-analyzer.cpp:7:5: note: 'x' initialized to a null pointer value
    int* x = nullptr;
    ^
/tmp/static-analyzer.cpp:8:9: note: Assuming 'argc' is <= 1
    if (argc > 1) {
        ^
/tmp/static-analyzer.cpp:8:5: note: Taking false branch
    if (argc > 1) {
    ^
/tmp/static-analyzer.cpp:11:18: note: Dereference of null pointer (loaded from variable 'x')
    printf("%d", *x);
                 ^

Example 2:

struct A {
    void foo(int bar);
};

void A::foo(int baz) {
}

clang-tidy output:

/tmp/name-mismatch.cpp:2:10: warning: function 'A::foo' has a definition with different parameter names [readability-inconsistent-declaration-parameter-name]
    void foo(int bar);
         ^
/tmp/name-mismatch.cpp:5:9: note: the definition seen here
void A::foo(int baz) {
        ^
/tmp/name-mismatch.cpp:2:10: note: differing parameters are named here: ('bar'), in definition: ('baz')
    void foo(int bar);
         ^
@mfenjiro
Copy link

Hey there,

I see you are using almost the same setup as me. I am trying to use clang-tidy, Jenkins, sonarqube and gerrit as a combo for my project. What is your experience with them ? What is your compile_commmands.json generator tool ? Have you find problems with it, clang-tidy and the parser of sonarscanner ?
Thank you in advance.

Best regards,

@guwirth
Copy link
Collaborator

guwirth commented Jul 26, 2019

Hi @jspam you can try with the snapshot https://ci.appveyor.com/project/SonarOpenCommunity/sonar-cxx/branch/master/artifacts. Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants