Issue 75755
Summary libc++: constexpr std::string does not work (clang 17)
Labels clang, libc++
Assignees
Reporter q66
    The following code:

```
#include <string>

constexpr std::string foo{"XX"};

int main() {
}
```

should compile, but instead it fails with:

```
test.cc:3:23: error: constexpr variable 'foo' must be initialized by a constant _expression_
    3 | constexpr std::string foo{"XX"};
      | ^~~~~~~~~
test.cc:3:23: note: pointer to subobject of heap-allocated object is not a constant _expression_
/usr/bin/../include/c++/v1/__memory/allocator.h:112:38: note: heap allocation performed here
  112 |             return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
      | ^
1 error generated.
```

I haven't been able to find anything about this being broken, and available resources list the functionality as available since 15.

This is a musl/libc++/compiler-rt environment, on x86_64 architecture, but probably should not matter. The libc++ has hardened mode on.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to