[Bug c++/93630] New: Multi-dimensional array initialization converts empty raw strings to NULL

rodrigorivascosta at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Feb 7 21:44:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93630

            Bug ID: 93630
           Summary: Multi-dimensional array initialization converts empty
                    raw strings to NULL
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rodrigorivascosta at gmail dot com
  Target Milestone: ---

Hello!

Consider the following C++ code:

```
#include <stdio.h>

struct Data
{
    const char *text;
};

const struct Data group[3][3] = 
{
    {
        {"AA"}, 
        {"AB"}, 
        {""}, 
    },
    {
        {"BA"}, 
        {""}, 
        {""}, 
    },
    {
        {""}, 
        {""}, 
        {"XX"}, 
    },
};

int main()
{
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
        {
            printf("'%s'\n", group[i][j].text);
        }
    return 0;
}
```

I'd expect to print the strings as they are in the code. Instead it prints:
'AA'
'AB'
'(null)'
'BA'
'(null)'
'(null)'
''
''
'XX'

That is, the trailing empty strings of each subarray are compiled as if they
were NULL.

Compiling it as C instead does print the expected output, as does with clang++-


More information about the Gcc-bugs mailing list