Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350144

Summary: [checker] suppressing the "No break at the end of case" problem with regexp
Product: [Tools] CDT Reporter: Mikhail Barg <mikhail.barg>
Component: cdt-codanAssignee: Elena Laskavaia <elaskavaia.cdt>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, nobody, scobido1984, waste.manager, yevshif, zeratul976
Version: 8.0   
Target Milestone: 9.5.0   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/114751
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=ce18aad766e9a947679a3daf33966bba75406fdf
Whiteboard:
Attachments:
Description Flags
example fix none

Description Mikhail Barg CLA 2011-06-23 10:05:17 EDT
Build Identifier: 20110615-0604

While the label "Comment text to suppress the problem (regular expression)" says that there could be a regular expression, I am unable to make it work.

I'm trying to suppress the problem with the comment "//no break here"

    switch (1)
    {
    case 1:
    	//no break here
    }

and the regexp "no break.*" but it keeps being reported. 
Some more investigation shows that the text seem to be used as is (regexp "no break.*" suppresses the "//no break.*" comment).


Reproducible: Always
Comment 1 Tomasz Wesolowski CLA 2011-07-28 13:27:15 EDT
org.eclipse.cdt.codan.internal.checkers.CaseBreakChecker:113:

> if (str.equalsIgnoreCase(_noBreakComment))

That's how it's done right now, good catch.

What's the plan here? I can change it to regex easily, got the fix already in a branch, but how exactly do we want it to work? Should it be case-insensitive by default? Do we want .find() (pattern present in comment) or .match() (pattern exactly matching comment)?
Comment 2 Tomasz Wesolowski CLA 2011-07-28 13:42:33 EDT
Created attachment 200547 [details]
example fix

this uses .find() and case insensitive matching
Comment 3 Mikhail Barg CLA 2011-07-29 03:42:20 EDT
> Do we want .find() (pattern present in comment) or .match() (pattern
> exactly matching comment)?

Hm, match() is more universal, but find() will be easier to user for most cases. I'm voting for find().
Comment 4 Gil Barash CLA 2011-07-30 10:35:55 EDT
In bug 352221 I supplied a patch for adding quick-fix support for this checker.

For the quick fix to be able to add a comment automatically, I used non-case-sensitive "beginsWith" (because a reg-ex like "no break.*" is a really ugly comment :-)
Comment 5 Nobody - feel free to take it CLA 2017-12-23 10:11:24 EST
It possible also check comment with regex ".*falls?[ \t-]*thr(ough|u).*" for this warning? Or allow use regular expression in additional field?

https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

One string comment is not enough.
Comment 6 Eclipse Genie CLA 2017-12-26 15:10:03 EST
New Gerrit change created: https://git.eclipse.org/r/114751
Comment 8 Elena Laskavaia CLA 2017-12-30 11:29:14 EST
fixed on master
Comment 9 Elena Laskavaia CLA 2017-12-30 11:29:51 EST
i.e it is now supports regular expression