public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode
@ 2021-08-12  8:54 fchelnokov at gmail dot com
  2021-08-12  9:06 ` [Bug c++/101873] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2021-08-12  8:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101873
           Summary: Compilation error of valid code with return local
                    variable in C++20 mode
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The program as follows fails to compile in C++20 mode:
```
struct U {
    U(int) {}
    U(int&&) {}
};

U foo(int a = 0) { return a; }

int main() { foo(); }
```
But it is a valid program and other compilers accept it:
https://gcc.godbolt.org/z/fMvEPMGhq

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

* [Bug c++/101873] Compilation error of valid code with return local variable in C++20 mode
  2021-08-12  8:54 [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode fchelnokov at gmail dot com
@ 2021-08-12  9:06 ` jakub at gcc dot gnu.org
  2021-08-12  9:57 ` fchelnokov at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-12  9:06 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is rejected since r11-2412-g1722e2013f05f1f1f99379dbaa0c0df356da731f
aka PR91427 fix.
Do the other compilers implement wg21.link/p1825 ?
Whether your testcase is valid or not I'll defer to others.

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

* [Bug c++/101873] Compilation error of valid code with return local variable in C++20 mode
  2021-08-12  8:54 [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode fchelnokov at gmail dot com
  2021-08-12  9:06 ` [Bug c++/101873] " jakub at gcc dot gnu.org
@ 2021-08-12  9:57 ` fchelnokov at gmail dot com
  2021-08-12 10:11 ` jakub at gcc dot gnu.org
  2021-08-15 11:56 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2021-08-12  9:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
Thanks, I assumed that the code is valid based on stackoverflow answer:
https://stackoverflow.com/questions/68747489/is-the-local-variable-returned-by-a-function-automatically-moved-in-c20

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

* [Bug c++/101873] Compilation error of valid code with return local variable in C++20 mode
  2021-08-12  8:54 [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode fchelnokov at gmail dot com
  2021-08-12  9:06 ` [Bug c++/101873] " jakub at gcc dot gnu.org
  2021-08-12  9:57 ` fchelnokov at gmail dot com
@ 2021-08-12 10:11 ` jakub at gcc dot gnu.org
  2021-08-15 11:56 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-12 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So questionable based on the status of https://wg21.link/p2266 and whether it
will be a DR or not?

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

* [Bug c++/101873] Compilation error of valid code with return local variable in C++20 mode
  2021-08-12  8:54 [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-12 10:11 ` jakub at gcc dot gnu.org
@ 2021-08-15 11:56 ` fchelnokov at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fchelnokov at gmail dot com @ 2021-08-15 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
If this question is to me, then actually I am not absolutely sure. I initially
thought that GCC was right in this code example. But later a high reputy C++
expert from stackoverflow dissuaded me. According to him, the code example was
valid in C++17 and remains valid in C++20. C++ standard is so complex nowdays.

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

end of thread, other threads:[~2021-08-15 11:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12  8:54 [Bug c++/101873] New: Compilation error of valid code with return local variable in C++20 mode fchelnokov at gmail dot com
2021-08-12  9:06 ` [Bug c++/101873] " jakub at gcc dot gnu.org
2021-08-12  9:57 ` fchelnokov at gmail dot com
2021-08-12 10:11 ` jakub at gcc dot gnu.org
2021-08-15 11:56 ` fchelnokov at gmail dot com

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