Does the following code have an undefined behaviour?

```
[[ gnu::pure ]]
static const MyClass &myClass() noexcept
{
    static const MyClass s_myClass;
    return s_myClass;
}

```

According to [gcc docs](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes), the `pure` attribute is for functions which have no effects except the return value and this return value depends only on the parameters and/or global variables.

On the one hand, this function does not have any observable effects other than its return value and it always returns the same value. So it is completely safe to optimise away multiple calls to this function. This is I think what the `pure` attribute is for.

On the other hand, this function needs to construct the `MyClass` object on the first invocation. This includes calling a `MyClass` constructor and setting an implicit *is-initialised* flag to true. This could count as an effect besides the return value (although it is not visible from the outside).

---

This code works on `gcc`, but `clang` optimises away the `MyClass` construction part and makes `myClass()` return an uninitialised object. A `clang` developer insists it is because of the undefined behaviour.

See this bug report: <https://bugs.llvm.org/show_bug.cgi?id=36750> (note it says `gnu::const`, but using `gnu::pure` produces the same result).