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

            Bug ID: 125426
           Summary: lambda with try block treated as constexpr in C++17
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aoliva at gcc dot gnu.org
  Target Milestone: ---

// { dg-do compile }
// { dg-options "-pedantic" }
auto l = []() /* constexpr */ {
  try { return 1; }
  catch (...) {}
};
static_assert(l() == 1); // { dg-error "non-constant" }

With -std=c++14, this reports that the static_assert expression is non-constant
because of the lambda call, and that the lambda is only implicitly constexpr in
C++17 and later.  Both are correct.

The note about implicit constexpr is displayed even if constexpr is explicit,
which doesn't seem correct, but that's not what this report is about.

In C++17, with an explicit constexpr, it warns that try blocks in constexpr
functions are only allowed in C++20.  That is also correct.

But then, with or without the explicit constexpr, it accepts the lambda in the
static assert, as if it were constexpr despite not satisfying the requirements.
 That does not seem correct.

Without the explicit constexpr, it does so without as much as a diagnostic. 
That is definitely incorrect.

Reply via email to