Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3715

GNU extensions should not be used

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Replace the use of this GNU extension with standard syntax.
    • Highlighting:
      Hide

      the extension

      Show
      the extension
    • 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;
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: