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

            Bug ID: 124145
           Summary: Repeat call to constexpr throwing function doesn't
                    throw
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ivan.lazaric.gcc at gmail dot com
  Target Milestone: ---

```
struct S {};

constexpr S tail(S x) {
  throw 123;
  return x;
}

constexpr inline void head() { tail(S{}); }

consteval {
  try {
    head();
    asm(""); // never reached
  } catch (int) {
  }

  try {
    head();
    asm(""); // somehow reached
  } catch (int) {
  }
}
```

Flags used for compilation: -std=c++26

`tail()` and `head()` unconditionally throw an int.
Second call to `head()` doesn't seem to throw, and the asm statement is
reached.

Compiler output:
```
in 'constexpr' expansion of '<lambda()> static()'
<source>:22:1:   
   22 | }
      | ^
<source>:19:5: error: inline assembly is not a constant expression
   19 |     asm(""); // somehow reached
      |     ^~~
<source>:19:5: note: only unevaluated inline assembly is allowed in a
'constexpr' function in C++20
Compiler returned: 1
```

Godbolt of example:
https://godbolt.org/z/zaoWEd7jG
  • [Bug c++/124145] New: Repea... ivan.lazaric.gcc at gmail dot com via Gcc-bugs

Reply via email to