17

Consider the following code:

struct A
{
    void foo(this auto &&) noexcept(true) {}
    auto bar() -> decltype(foo()) {}
};

Clang 19 rejects this code with the error below, while GCC and MSVC accept it.

<source>:4:28: error: exception specification is not available until end of class definition
    4 |     auto bar() -> decltype(foo()) {}
      |                            ^

Is this code somehow illegal, or is it a Clang bug? If it's illegal, why? (Why can't the exception specfification be available at this point?)


To be clear, my actual noexcept(...) depends on this, so removing (true) isn't an option.

Also if I start using this in it, GCC starts crashing: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117106

4
  • The return type is not part of the complete class context so not sure if its a bug or clang is the correct one. Commented Oct 12, 2024 at 14:11
  • auto bar() { return foo(); } is accepted by Clang as well. Commented Oct 12, 2024 at 19:08
  • I think this may be a version of CWG2335 Commented Oct 12, 2024 at 23:23
  • 5
    github.com/llvm/llvm-project/issues/36907 Commented Oct 13, 2024 at 8:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.