Skip to content

C23 constexpr should not have external linkage #97830

@gustedt

Description

@gustedt

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

Metadata

Metadata

Assignees

Labels

c23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions