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

            Bug ID: 118335
           Summary: [C23] a non-null ptr allowed for constexpr when using
                    compound literal constant literals
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
typedef struct {
        int *a;
} foo;
int b = 42;
constexpr foo bar1 = (foo){.a = &b}; /* { dg-error "pointer initializer is not
null" } */
constexpr foo bar2 = {.a = &b}; /* { dg-error "pointer initializer is not null"
} */
```

GCC currently allows bar1 since it seems like there is order issue of emitting
the `pointer initializer is not null` error as we don't look into the compound
literal to see if a pointer is not null.

Reply via email to