llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.98k stars 11.55k forks source link

Implement P2752R3 Static storage for braced initializers #104487

Open cor3ntin opened 1 month ago

cor3ntin commented 1 month ago

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2752r3.html

llvmbot commented 1 month ago

@llvm/issue-subscribers-clang-frontend

Author: cor3ntin (cor3ntin)

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2752r3.html
efriedma-quic commented 1 month ago

Note that gcc currently puts the resulting initializer_list constant in non-mergeable rodata for locals. I'm not sure if this is a reaction to the constexpr evaluation rules, or something else.

Related fun: the following prints "0 1" in gcc. We should make sure we don't do the same thing.

#include <initializer_list>
#include <cstdio>
static constexpr std::initializer_list<char> a = {'b','c','\0'};
static constexpr std::initializer_list<char> b = {'b','c','\0'};

int main() {
    const char* volatile aaa = a.begin();
    const char* volatile bbb = b.begin();
    printf("%d %d\n", a.begin() == b.begin(), aaa == bbb);
}