llvm / llvm/llvm-project

[libc++] direct-initialized engaged -> disengaged std::optional incorrectly deemed not a constant expression

Open
#192,852 10 comments 0 reactions 0 assignees View on GitHub
constexpr libc++
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following snippet is rejected by Clang + libc++ (doesn't seem to be a regression):

```c++
#include

struct B {
constexpr B(int m) : m(m) { }
constexpr ~B() { }
int m;
};

static_assert(!std::is_trivially_destructible_v);

struct C : std::optional {
constexpr C() : std::optional(1) { this->reset(); }
};
constexpr C c;
```
```
:14:13: error: constexpr variable 'c' must be initialized by a constant expression
14 | constexpr C c;
| ^
:14:13: note: subobject '__val_' is not initialized
```

https://godbolt.org/z/rnncqhcY6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.