Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-3288

S5276: Fix false-positives when using "-fshort-enums"

    XMLWordPrintable

    Details

      Description

      We should consider "-fshort-enums" in GCC and Clang based drivers, clang::LangOptions has ShortEnums flags which should be enabled.

      Reproducer from report:

      typedef enum {
        enum_value_0 = 0,
        enum_value_1
      } short_enum_t;
      
      int func(unsigned char p)
      {
        return p;
      }
      
      int main(void)
      {
        short_enum_t val = enum_value_1;
        return func(val); // <-- code smell, implicit conversion loses integer precision: 'short_enum_t' to 'uint8_t' (aka 'unsigned char')
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marco.antognini Marco Antognini
              Reporter:
              massimo.paladin Massimo PALADIN
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: