public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110197] New: Empty constexpr object constructor erronously claims out of range access
@ 2023-06-09 18:29 matt at godbolt dot org
  2023-06-09 18:37 ` [Bug c++/110197] [13/14 Regression] " mpolacek at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: matt at godbolt dot org @ 2023-06-09 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110197
           Summary: Empty constexpr object constructor erronously claims
                    out of range access
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
  Target Milestone: ---

The following code, compiled on GCC 13.1 complains of a non-constexpr safe
array access:

```
#include <array>
#include <string_view>

struct Currency {
    // commenting-in the `i` below fixes, as does passing a `const char *` to
the ctor
    // int i{};
    constexpr explicit Currency(std::string_view name) {}
    // constexpr explicit Currency(const char *name) {}
};

static Currency get_c() {
    static constexpr std::array c{Currency{"BWP"}};
    return c[0];
}
```

The error is:

```
<source>: In function 'Currency get_c()':
<source>:12:50:   in 'constexpr' expansion of
'Currency(std::basic_string_view<char>(((const char*)"BWP")))'
<source>:12:50: error: accessing uninitialized array element
   12 |     static constexpr std::array c{Currency{"BWP"}};
      |                                                  
```

The same code compiles without issue on GCC 12.1, and on clang. Passing either
a const char * to the constructor, or adding a single field to the class makes
it compile.

https://godbolt.org/z/G355frEM4

Was also reproducible on trunk as of 14da764809d3bffe9336e72999312ba3fb019dc6

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-08-21 14:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-09 18:29 [Bug c++/110197] New: Empty constexpr object constructor erronously claims out of range access matt at godbolt dot org
2023-06-09 18:37 ` [Bug c++/110197] [13/14 Regression] " mpolacek at gcc dot gnu.org
2023-06-09 18:40 ` mpolacek at gcc dot gnu.org
2023-07-18 18:15 ` mpolacek at gcc dot gnu.org
2023-07-19 15:14 ` ppalka at gcc dot gnu.org
2023-07-20 16:51 ` ppalka at gcc dot gnu.org
2023-07-27  9:26 ` rguenth at gcc dot gnu.org
2023-07-27 13:10 ` cvs-commit at gcc dot gnu.org
2023-07-27 13:11 ` [Bug c++/110197] [13 " ppalka at gcc dot gnu.org
2023-07-27 13:27 ` matt at godbolt dot org
2023-08-07 23:27 ` cvs-commit at gcc dot gnu.org
2023-08-21 14:04 ` ppalka at gcc dot gnu.org
2023-08-21 14:09 ` matt at godbolt dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).