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

Bug 356037

Summary: "No break at the end of case" warning for a case statement produced by macro expansion
Product: [Tools] CDT Reporter: Sergey Prigogin <eclipse.sprigogin>
Component: cdt-codanAssignee: Sergey Prigogin <eclipse.sprigogin>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: normal    
Priority: P3 CC: cdtdoug, zeratul976
Version: 8.0   
Target Milestone: 8.0.1   
Hardware: All   
OS: All   
Whiteboard:

Description Sergey Prigogin CLA 2011-08-28 22:23:30 EDT
There should be no "No break at the end of case" warning if the case statement is a result of macro expansion:

#define MY_MACRO(i) \
  case i: {         \
  }

void f() {
  int x;
  switch (x) {
    MY_MACRO(1)  // There should be no warning here.
  }
}
Comment 1 Sergey Prigogin CLA 2011-08-28 22:37:24 EDT
Fixed in master and cdt_8_0 > 20110828.
Comment 2 CDT Genie CLA 2011-08-28 23:23:02 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 356037 - &quot;No break at the end of case&quot; warning for a case statement
    produced by macro expansion.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c0b9f79b300f27293e507c7c050afe4befa86928
Comment 3 CDT Genie CLA 2011-08-28 23:23:03 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 356037 - &quot;No break at the end of case&quot; warning for a case statement
    produced by macro expansion.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=dce3efe73399ecb1c1c2bd810800aa7e9c5f453a
Comment 4 Nathan Ridge CLA 2015-02-14 20:40:47 EST
Sergey, what is the rationale for this special treatment of macros?
Comment 5 Sergey Prigogin CLA 2015-02-16 00:33:49 EST
(In reply to Nathan Ridge from comment #4)
> Sergey, what is the rationale for this special treatment of macros?

Showing warnings in the code that is a result of macro expansion is confusing to the user since the user doesn't see the suspicious code. It may also lead to a large number of warnings for the same macro if that macro is used in many places.
Comment 6 Nathan Ridge CLA 2015-02-16 00:56:48 EST
(In reply to Sergey Prigogin from comment #5)
> (In reply to Nathan Ridge from comment #4)
> > Sergey, what is the rationale for this special treatment of macros?
> 
> Showing warnings in the code that is a result of macro expansion is
> confusing to the user since the user doesn't see the suspicious code. It may
> also lead to a large number of warnings for the same macro if that macro is
> used in many places.

Isn't there the chance of catching a real bug, though, if you use the macro multiple times in the same switch, and you forgot the 'break' in the macro definition?
Comment 7 Sergey Prigogin CLA 2015-02-16 02:06:05 EST
(In reply to Nathan Ridge from comment #6)
> Isn't there the chance of catching a real bug, though, if you use the macro
> multiple times in the same switch, and you forgot the 'break' in the macro
> definition?

It's better to miss a real bug than to produce false positives.