How do I turn off a static code analysis warning on a line by line warning in CDT (C code)?

后端 未结 7 1070
一向
一向 2021-01-17 13:19

We have a project using CDT in Eclipse. It\'s an old project that we just imported into Eclipse, and I want to ensure we start using static code analysis to find any weirdn

相关标签:
7条回答
  • 2021-01-17 13:40

    You should try

    //no break
    

    before the next case.

    0 讨论(0)
  • 2021-01-17 13:46

    Solved it.

    I just added the text from the warning that I wanted to ignore to immediately above where the break would be.

    Like this:

          case enChC:
            ++nChannel;
            //No break at the end of case
          case enChD:
            ++nChannel;
    
    0 讨论(0)
  • 2021-01-17 13:47

    You have to upgrade to Eclipse Oxygen.3 (or.2).

    Beginning with these versions warnings/markers can be suppressed by simply using "Quick Fix".

    0 讨论(0)
  • 2021-01-17 13:47

    These settings are located under Window -> Preferences -> C/C++ -> Code Analysis. You can customize the settings. For example if you pick No break at the end of case, you can define the comment that suppresses the warning. By default it's "no break". So coincidentally copy/pasting the warning message into the comment worked in your case:

    CDT static code analysis

    As you can see the text doesn't have to be an exact match and it doesn't seem to be case sensitive either.

    Referring to your follow-up question about unused variables: When you customize Unused variable in file scope you can define variable names that should be ignored:

    enter image description here There are two cryptic predefined exceptions "@(#)" and "$Id". Unfortunately I couldn't find any official documentation so I went looking into the source. It looks like the checker simply tests if a variable name contains() any of the specified exceptions. If it does, the warning is suppressed.

    Outside of Eclipse CDT, there's the popular void-casting trick. If the compiler warns about an unused variable, cast it to void. This operation has no effect, so it's safe, but from the perspective of the compiler that variable is now used. I usually wrap it in a macro to make abundantly clear what I'm doing, e.g.

    #define UNUSED(var) (void)(var)
    
    void foobar()
    {
        int b;     // not used. 
        UNUSED(b); // now it's used
    }
    
    0 讨论(0)
  • 2021-01-17 13:54

    As is has been said, in this specific case, it can be solved adding the comment:

    //no break
    

    or:

    //no break at the end of case
    

    What really matters is the (no break).

    But also, it is required that you don't have more comments between the end of this case and the next one or it won't work. For example the next case will still result in a warning:

    case enChC:
        ++nChannel;
        //No break
        //This second case decrease the value
      case enChD:
        ++nChannel;
    
    0 讨论(0)
  • 2021-01-17 14:00

    To disable the annoying notifications, you need to go to Preferences->C/C++->Editor, and then uncheck the options that say "Highlight inactive code", "Display problems as you type", etc. Hope this helps.

    0 讨论(0)
提交回复
热议问题