[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 27 14:37:35 PDT 2024
zygoloid wrote:
I found this: https://fuchsia.googlesource.com/third_party/github.com/fmtlib/fmt/+/refs/heads/upstream/main/include/fmt/base.h#2664
Note that this is passing `s` separately both to `parse_format_string` and to `checker`. Here, `s` is a lambda that implicitly converts to a string view by evaluating a string literal. Those two evaluations can return different string literal objects, and I'm assuming pointers to those strings are what we end up subtracting.
So yes, this fmtlib code is wrong -- it's incorrectly assuming that a string literal will always evaluate to the same value, which is not true at runtime or (after this Clang change) at compile time. The correct thing to do would be what is done a few lines below in the next constructor: convert the `S` object to a string view once, and then use that same value for both calls.
https://github.com/llvm/llvm-project/pull/109208
More information about the cfe-commits
mailing list