Issue 61562
Summary Destroying an object during a call to construct_at erroneously rejected during constant evaluation
Labels new issue
Assignees
Reporter davidstone
    The following valid (I think) translation unit

```cpp
#include <memory>

struct ref_holder {
	constexpr explicit ref_holder(int & value):
		m_value(value)
	{
	}

	constexpr operator int() const {
		using T = int;
		m_value.~T();
		return int();
	}

private:
	int & m_value;
};

constexpr bool f() {
	int x = 0;
	std::construct_at(&x, ref_holder(x));
	return true;
}

static_assert(f());
```

is rejected by clang with

```console
<source>:25:15: error: static assertion _expression_ is not an integral constant _expression_
static_assert(f());
 ^~~
<source>:11:3: note: destruction of object outside its lifetime is not allowed in a constant _expression_
                m_value.~T();
 ^
/opt/compiler-explorer/clang-assertions-trunk-20230319/bin/../include/c++/v1/__memory/construct_at.h:38:50: note: in call to '&ref_holder(x)->operator int()'
  return ::new (std::__voidify(*__location)) _Tp(std::forward<_Args>(__args)...);
 ^
<source>:21:2: note: in call to 'construct_at(&x, ref_holder(x))'
        std::construct_at(&x, ref_holder(x));
        ^
<source>:25:15: note: in call to 'f()'
static_assert(f());
              ^
1 error generated.
Compiler returned: 1
```

See it live: https://godbolt.org/z/T6Wo6rd6d
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to