0 Replies Latest reply on Oct 28, 2019 10:58 PM by koval

    In-class initializer for char array field fails without braces


      Studio 12.6 fails to compile the following code:

      class C {
          char field[10] = "";


      "initializer.cpp", line 2: Error: Cannot use const char[1] to initialize char[10].

      1 Error(s) detected.


      To make it work I need to add braces around the string literal.

      class C {
        char field[10] = {""};


      This seems inconsistent with gcc and clang which accept the original code. It is also inconsistent with same initializer for global or local variables.

      char global[10] = "";
      void f()
          char local[10] = "";
          static char local_static[10] = "";


      I would expect initialization of class fields to be treated same.

      Is this a bug in CC or some subtle wording in the standard which neither gcc nor clang implement?