public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115233] New: constexpr RVO result is not determined as constant epression
@ 2024-05-26 12:16 konstantin.vladimirov at gmail dot com
  2024-05-26 12:18 ` [Bug c++/115233] " pinskia at gcc dot gnu.org
  2024-05-26 12:20 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: konstantin.vladimirov at gmail dot com @ 2024-05-26 12:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115233
           Summary: constexpr RVO result is not determined as constant
                    epression
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: konstantin.vladimirov at gmail dot com
  Target Milestone: ---

Consider I have this type:

---

struct Type {
  int a;
  const int& b;
  constexpr Type() : a(1), b(a) {}
};

constexpr Type t1;
constexpr int c11 = t1.a;
constexpr int c12 = t1.b;

---

c11 and c12 are fine for both gcc and clang

Now lets introduce constexpr function which is subject to RVO:

constexpr auto get() {
  return Type();
}

Now try this:

constexpr Type t2 = get();
constexpr int c2 = t2.a;

This code compiles fine with clang but not with gcc.

Live example on godbolt: https://godbolt.org/z/zf3YvebbG

According to [expr.const] and [class.copy.elision] result of constexpr function
is necessary RVO and is contant expression, so t2 construction is fine and t2.a
is constant expression as well.

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

* [Bug c++/115233] constexpr RVO result is not determined as constant epression
  2024-05-26 12:16 [Bug c++/115233] New: constexpr RVO result is not determined as constant epression konstantin.vladimirov at gmail dot com
@ 2024-05-26 12:18 ` pinskia at gcc dot gnu.org
  2024-05-26 12:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-26 12:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It also compiles fine with MSVC.

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

* [Bug c++/115233] constexpr RVO result is not determined as constant epression
  2024-05-26 12:16 [Bug c++/115233] New: constexpr RVO result is not determined as constant epression konstantin.vladimirov at gmail dot com
  2024-05-26 12:18 ` [Bug c++/115233] " pinskia at gcc dot gnu.org
@ 2024-05-26 12:20 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-26 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-05-26
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2024-05-26 12:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-26 12:16 [Bug c++/115233] New: constexpr RVO result is not determined as constant epression konstantin.vladimirov at gmail dot com
2024-05-26 12:18 ` [Bug c++/115233] " pinskia at gcc dot gnu.org
2024-05-26 12:20 ` pinskia at gcc dot gnu.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).