llvm / llvm-project

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

C23 constexpr should not have external linkage #97830

Closed gustedt closed 1 week ago

gustedt commented 1 week ago

Hi, thanks for implementing constexpr for clang-19!

The following code

constexpr int category_width = 5;
int const w = 5;
int const* a = &category_width;

compiles, but produces an external symbol for category_width and then multiple defined symbol errors on linkage. So I cannot use constexpr in header files, or I'd have to prefix it with static, which defeats the purpose of constexpr ...

C23 has in 6.2.2 p3

If the declaration of a file scope identifier for: — an object contains any of the storage-class specifiers static or constexpr; — or, a function contains the storage-class specifier static, then the identifier has internal linkage.

Thanks Jens

llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-frontend

Author: Jens Gustedt (gustedt)

Hi, thanks for implementing `constexpr` for clang-19! The following code ```{.C} constexpr int category_width = 5; int const w = 5; int const* a = &category_width; ``` compiles, but produces an external symbol for `category_width` and then multiple defined symbol errors on linkage. So I cannot use `constexpr` in header files, or I'd have to prefix it with `static`, which defeats the purpose of `constexpr` ... C23 has in 6.2.2 p3 > If the declaration of a file scope identifier for: > — an object contains any of the storage-class specifiers `static` or `constexpr`; > — or, a function contains the storage-class specifier `static`, > then the identifier has internal linkage. Thanks Jens
chestnykh commented 1 week ago

Can i assign this issue to myself?