-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format string checking incorrectly assumes repeated evaluation of string literal will produce the same pointer #4177
Comments
Applied the patch (with a small tweak) in cacc310. Thanks! |
@vitaut FMT_CONSTEXPR auto sv = string_view(S()); ? Instead of FMT_CONSTEXPR auto sv = string_view(s); ?
|
I don't think it matters much but since the object is already available, I don't see why we need to construct another one. |
Adding a regression test: 1c5883b. |
Nevermind, I misinterpreted which is the current version of the code. You are right, we could use |
I did some local test by rolling our fmtlib to ToT and building our project with ToT clang but still getting errors:
and
|
I guess we should be using |
You mean |
You would also need to remove the |
With diff like this:
The build passed. |
Uploaded PR #4187 |
In the
fstring
constructor from a type that is convertible to string view, thes
argument is passed to two different functions, which both internally convert it to astring_view
. Thiss
argument is frequently created by theFMT_STRING
macro which has a conversion tostring_view
that evaluates a string literal expression.Each evaluation of a string literal expression can produce a different pointer. Therefore it is not correct to assume that the two conversions of
s
to astring_view
produce relatedstring_view
s, but the code does assume this. Historically, compilers have let you get away with this in compile-time evaluation, but clang recently gained a more strict implementation of this rule and now rejects.I think the fix is probably to do the same thing in this constructor that is done a few lines below in the next constructor:
The text was updated successfully, but these errors were encountered: