public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112553] New: noexcept lambda does not generate call to terminate
@ 2023-11-15 19:44 federico at kircheis dot it
  2023-11-15 20:03 ` [Bug c++/112553] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: federico at kircheis dot it @ 2023-11-15 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112553
           Summary: noexcept lambda does not generate call to terminate
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: federico at kircheis dot it
  Target Milestone: ---

Consider following example

----
void do_something();

void bar(){
    []() noexcept{
    do_something();
    }();
}

----


If "do_something" throws, as the lambda is marked noexcept, there should be a
call to std::terminate, but it is not the case: https://godbolt.org/z/xjqzTdrWG

clang and msvc generate the call to std::terminate

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

* [Bug c++/112553] noexcept lambda does not generate call to terminate
  2023-11-15 19:44 [Bug c++/112553] New: noexcept lambda does not generate call to terminate federico at kircheis dot it
@ 2023-11-15 20:03 ` pinskia at gcc dot gnu.org
  2023-11-15 20:22 ` redi at gcc dot gnu.org
  2023-11-15 20:27 ` federico at kircheis dot it
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-15 20:03 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
```
#include <stdio.h>

[[gnu::noipa, gnu::noinline]]
void do_something()
{
        throw 1;
}

void bar(){
    []() noexcept{
    do_something();
    }();
}

int main()
{
        try {
        bar();
        }catch(...) { printf("incorrectly caught eh.\n"); }
}
```
Works as expected and std::terminate gets called.
I don't see a reason to directly call std::terminate here if it is going to be
called from the personality function.

The original issue where this would be an issue was fix a while back. Anyways
at -O1 tail calls are not enabled even so you can't run into the original
issue.

See PR 82081 also.

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

* [Bug c++/112553] noexcept lambda does not generate call to terminate
  2023-11-15 19:44 [Bug c++/112553] New: noexcept lambda does not generate call to terminate federico at kircheis dot it
  2023-11-15 20:03 ` [Bug c++/112553] " pinskia at gcc dot gnu.org
@ 2023-11-15 20:22 ` redi at gcc dot gnu.org
  2023-11-15 20:27 ` federico at kircheis dot it
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-11-15 20:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Federico Kircheis from comment #0)
> If "do_something" throws, as the lambda is marked noexcept, there should be
> a call to std::terminate, but it is not the case:
> https://godbolt.org/z/xjqzTdrWG

Nothing in the standard supports your claim. The standard only says that
std::terminate is invoked, not that a call to it must appear in the assembly
code for the function.

G++ will invoke std::terminate in a complete example as Andrew showed. And it
does it with smaller, more cache-friendly code.

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

* [Bug c++/112553] noexcept lambda does not generate call to terminate
  2023-11-15 19:44 [Bug c++/112553] New: noexcept lambda does not generate call to terminate federico at kircheis dot it
  2023-11-15 20:03 ` [Bug c++/112553] " pinskia at gcc dot gnu.org
  2023-11-15 20:22 ` redi at gcc dot gnu.org
@ 2023-11-15 20:27 ` federico at kircheis dot it
  2 siblings, 0 replies; 4+ messages in thread
From: federico at kircheis dot it @ 2023-11-15 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Federico Kircheis <federico at kircheis dot it> ---
I stand corrected, sorry for the report.


Where can I find official information/documentation about the personality
function used by gcc?

The fact that clang and msvc handle this case differently made me believe gcc
was incorrect.

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

end of thread, other threads:[~2023-11-15 20:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-15 19:44 [Bug c++/112553] New: noexcept lambda does not generate call to terminate federico at kircheis dot it
2023-11-15 20:03 ` [Bug c++/112553] " pinskia at gcc dot gnu.org
2023-11-15 20:22 ` redi at gcc dot gnu.org
2023-11-15 20:27 ` federico at kircheis dot it

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