Bug 97664 - constexpr evaluation incorrectly accepts non-constant destruction
Summary: constexpr evaluation incorrectly accepts non-constant destruction
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2020-11-01 15:50 UTC by Luke Dalessandro
Modified: 2023-07-06 07:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Dalessandro 2020-11-01 15:50:32 UTC
This one involves some language-lawyering, which is not my forte.

While developing a constexpr, array-based vector that supports non-default constructible types, I have run into the following inconsistency between clang and gcc. 

https://godbolt.org/z/PYdq5P

```
#include <memory>

struct Foo {
    mutable int n = 0;
};

union U {
    Foo foo;
    constexpr U() {}
};

struct cvector {
    U storage[1];
    constexpr cvector() {
        std::construct_at(&storage[0].foo);
    }
    constexpr ~cvector() {
        std::destroy_at(&storage[0].foo);
    }
};

constexpr cvector v;
```

After some slack discussion that I didn't entirely follow, it seems that http://eel.is/c++draft/expr.const#7.2 combined with http://eel.is/c++draft/expr.const#6.2 may exclude the constexpr use of destroy_at of an instance of a class with mutable members. I am not confident with this analysis, nor am I confident that this is desirable behavior, but am reporting it for consideration.