I have the following code:
struct S {
// conditional noexcept specification which depends on noexceptness of foo()
void bar() noexcept(noexcept(foo()));
// conditional noexcept specification (true)
void foo() noexcept(true);
};
Clang rejects this code but GCC allows it (https://godbolt.org/z/nxqa5Tr1x):
<source>:2:34: error: exception specification is not available until end of class definition
2 | void bar() noexcept(noexcept(foo()));
|
Replacing noexcept(true) with noexcept is allowed by both compilers.
Questions
- Why would
noexcept(true)fail butnoexceptwork? - Which compiler conforms with the standard, if any?
Note: this example is obviously minimal. My actual use case is that I have a clear() member function which is noexcept only if clear_impl() is noexcept, in a custom container.
noexceptandnoexcept(true)should have different behaviour.Sis complete (e.g. you can see the full list of members ofS), but it does not imply that within a noexcept-specifier, you have access to information that is in later complete-class contexts. In some complete-class contexts, some compilers don't even let you access information that is in earlier complete-class contexts of a different kind, and the wording is not clear enough to say for sure that this is a compiler bug. I explain in more detail here.