public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110999] New: GCC rejects static variable with constexpr storage from inline method definition
@ 2023-08-12  4:44 danakj at orodu dot net
  0 siblings, 0 replies; only message in thread
From: danakj at orodu dot net @ 2023-08-12  4:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110999
           Summary: GCC rejects static variable with constexpr storage
                    from inline method definition
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danakj at orodu dot net
  Target Milestone: ---

Godbolt: https://godbolt.org/z/srvhxjqqz

GCC will accept it if the method definition comes after the `constexpr` storage
definition. But it rejects it if the method definition is inline in the class.

```
struct OutOfLine {
    static const OutOfLine kConstant;
    constexpr int f();
    int i = 2;
};
inline constexpr OutOfLine OutOfLine::kConstant;
// Accepted.
constexpr int OutOfLine::f() { return kConstant.i; }

struct InLine {
    static const InLine kConstant;
    // Rejected.
    constexpr int f() { return kConstant.i; }
    int i = 2;
};
inline constexpr InLine InLine::kConstant;

int main() {
    constexpr int x = OutOfLine().f();
    constexpr int y = InLine().f();
}
```

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-12  4:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-12  4:44 [Bug c++/110999] New: GCC rejects static variable with constexpr storage from inline method definition danakj at orodu dot net

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).