public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116418] New: [11/12/13/14/15 Regression] Nested statement expressions with decltype auto in template break
@ 2024-08-19 15:58 valentin at tolmer dot fr
  2024-08-19 16:10 ` [Bug c++/116418] [12/13/14/15 " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: valentin at tolmer dot fr @ 2024-08-19 15:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 116418
           Summary: [11/12/13/14/15 Regression] Nested statement
                    expressions with decltype auto in template break
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: valentin at tolmer dot fr
  Target Milestone: ---

$ cat source.cpp
template <typename>
void fn() {
  ({ decltype(auto) v = ({3;}); }); // breaks
  ({ auto v = ({3;}); });           // works
}
void fn2() {
  ({ decltype(auto) v = ({3;}); });  // works
}
$ g++ -std=c++20 source.cpp -c -O0
$ g++ -std=c++20 source.cpp -c -O1
source.cpp: In function 'void fn()':
source.cpp:3:30: error: statement-expression in a constant expression
[-Wtemplate-body]
    3 |   ({ decltype(auto) v = ({3;}); }); // breaks
      |                              ^
Compiler returned: 1

I tested it on godbolt, and it works on GCC 10.5, but not in 11.1, all the way
up to trunk. It's dependent on the optimizations, I've had some form of it
happen in our codebase in different places depending on the compiler version
(so upgrading GCC becomes a breaking change).
I tried to pinpoint the optimization that causes the diagnosis, but listing all
the flags for -O1 in https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
doesn't trigger the issue; adding -O1 does. Similarly, adding -O1 and disabling
all these flags triggers the issue.

Note that the templated function doesn't have to be templated to trigger the
bug.

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

end of thread, other threads:[~2024-09-20 22:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-19 15:58 [Bug c++/116418] New: [11/12/13/14/15 Regression] Nested statement expressions with decltype auto in template break valentin at tolmer dot fr
2024-08-19 16:10 ` [Bug c++/116418] [12/13/14/15 " pinskia at gcc dot gnu.org
2024-08-20  7:36 ` rguenth at gcc dot gnu.org
2024-08-20 13:54 ` valentin at tolmer dot fr
2024-08-20 17:21 ` [Bug c++/116418] [12/13/14/15 Regression] statement expressions as initializer for decltype auto breaks in templates with optimization turned on pinskia at gcc dot gnu.org
2024-09-03 15:57 ` jakub at gcc dot gnu.org
2024-09-03 15:59 ` [Bug c++/116418] [12/13/14/15 Regression] statement expressions as initializer for decltype auto breaks in templates with optimization turned on and debug info " pinskia at gcc dot gnu.org
2024-09-03 16:03 ` pinskia at gcc dot gnu.org
2024-09-03 16:08 ` [Bug c++/116418] [12/13/14/15 Regression] statement expressions as initializer for decltype auto breaks in templates with optimization turned on and debug info turned on due to gstatement-frontiers jakub at gcc dot gnu.org
2024-09-03 16:08 ` jakub at gcc dot gnu.org
2024-09-03 16:18 ` jakub at gcc dot gnu.org
2024-09-11  0:39 ` ppalka at gcc dot gnu.org
2024-09-12 16:45 ` cvs-commit at gcc dot gnu.org
2024-09-20 22:10 ` cvs-commit at gcc dot gnu.org
2024-09-20 22:10 ` [Bug c++/116418] [12/13 " ppalka 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).