[clang] [clang] implement current direction of CWG2765 for string literal comparisons in constant evaluation (PR #109208)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 12:30:15 PDT 2024


zygoloid wrote:

> I worry about string literals in vague-linkage entities, because the "version" of the string literal which is referred to from an inline-function/variable at runtime may not actually be the same version of the string literal seen in the current compilation -- at runtime we may in fact be using a different version of the symbol from another TU.

I think string literals in inline functions shouldn't be a problem by themselves -- each evaluation of the string literal is allowed to produce a different object, and each constant evaluation will produce a different version. But I think there is a problem in general for string literals that appear in the evaluated value of a vague linkage constant. For example:
```c++
constexpr inline const char *s = "foo";
```
... is required by the standard to have the same value across all translation units, but we currently don't ensure that's the case. I think that's a separable issue from this PR, but it's clearly related -- though I think probably the right answer here is for the ABI to assign a mangling to the string literal in this case. See https://github.com/itanium-cxx-abi/cxx-abi/issues/78 and https://github.com/llvm/llvm-project/issues/57957.

https://github.com/llvm/llvm-project/pull/109208


More information about the cfe-commits mailing list