Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Message:Replace the use of this GNU extension with standard syntax.
-
Highlighting:
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Covered Languages:C, C++, Objective-C
-
Irrelevant for Languages:ABAP, C#, Cobol, CSS, Flex, HTML, Java, JavaScript, PHP, PL/I, PL/SQL, Python, RPG, Swift, VB.Net, VB6, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources, Test Sources
Description
Proprietary compiler extensions can be handy, but they commit you to always using that compiler. This rule raises an issue when the following GNU extensions are used:
- A array initializer without =, which has been obsolete since GCC 2.5
- A structure member initializer with a colon, which has been obsolete since GCC 2.5.
- Case ranges
- Ternary operator with omitted second operand
Noncompliant Code Example
struct S { int f; }; struct S s[] = { [0] { // Noncompliant f : 0 // Noncompliant } }; int fun(int p) { switch (p) { case 0 ... 1: // Noncompliant do_the_thing(); break; case 2: //... } return p ?: 0; // Noncompliant }
Compliant Solution
struct S { int f; }; struct S s[] = { [0] = { .f = 0 } }; int fun(int p) { switch (p) { case 0: case 1: do_the_thing(); break; case 2: //... } return p ? p: 0; }