https://bugs.llvm.org/show_bug.cgi?id=48606

            Bug ID: 48606
           Summary: Clang rejects creation of struct with mutable member
                    during constant evaluation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

Consider the following code with C++20:
```
#include <memory>
struct WithMutable {
    mutable int val_{0};
};

constexpr bool createOnStack() {
    [[maybe_unused]] volatile WithMutable var;
    return true;
}

constexpr bool createOnHeap() {
    WithMutable* var = new WithMutable{};
    delete var;
    return true;
}

constexpr bool createWithAllocator() {
    WithMutable* var = std::allocator<WithMutable>{}.allocate(1);
    std::construct_at(var); 
    std::destroy_at(var);   
    std::allocator<WithMutable>{}.deallocate(var, 1);
    return true;
}

int main() {
    static_assert(createOnStack());
    static_assert(createOnHeap());
    static_assert(createWithAllocator());
}
```

Clang trunk rejects the last function `createWithAllocator` with the error
message: 
    "construction of mutable member 'val_' is not allowed in a constant
expression"

However, I cannot find any restriction on construction of mutable members
during a constant expression. Given that the other two functions are accepted
it is unclear why clang rejects the call to std::construct_at

(Godbolt link: https://godbolt.org/z/71zb7j)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to