| Issue |
169828
|
| Summary |
clang fails to compile valid constexpr default constructor
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
jodyhagins
|
The following code declares a trivial `default` default constructor when `use_trivial` is true, and implements a non-trivial default constructor that initializes the value to zero, when `use_trivial` is `false`.
This is valid according to my reading of the standard, and it compiles as expected on all versions of gcc from version 10 up to the current version. It fails to compile on all versions of clang that support C++20.
Specifically, the line defining `blarg1` gets an error like `error: constexpr variable 'blarg1' must be initialized by a constant _expression_`.
```c++
template <typename T> inline constexpr bool use_trivial = true;
template <> inline constexpr bool use_trivial<int> = false;
template <typename T>
struct Blarg
{
T _;
constexpr Blarg() noexcept
requires(not use_trivial<T>)
: _(0)
{ }
constexpr Blarg() noexcept
requires use_trivial<T>
= default;
};
static_assert(std::is_default_constructible_v<Blarg<unsigned>>);
static_assert(std::is_trivially_default_constructible_v<Blarg<unsigned>>);
constexpr Blarg<unsigned> blarg0{};
static_assert(std::is_default_constructible_v<Blarg<int>>);
static_assert(not std::is_trivially_default_constructible_v<Blarg<int>>);
constexpr Blarg<int> blarg1;
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs