-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
clang-format breaks code by splitting a string in a macro call. #17496
Comments
This is an MSVC bug. Per [lex.string]p13, "If one string literal has no encoding-prefix, it is treated as a string literal of the same encoding-prefix as the other operand." It's not clear to me how practical it would be for us to work around this bug. =( |
This is a really common Windows idiom, so I think we should try to support it. It doesn't seem too hard. Wrap: To: And we should recognize it by finding a string literal inside of a '_T(...)' like thing. |
What exactly is a "_T(...)" like thing? If we are looking for exactly for the identifier _T, this could work. Otherwise, I think we would have to be absolutely sure that it is a macro defined as "L##x", because basically everything else will break with this change. Seems like a big risk to work around a compiler bug. Alternatively, we could detect this pattern and not insert a break. |
Yea, I was thinking to look for exactly '_T' preceding a parenthesis.
My impression is that this is not dissimilar to the _(...) trick used in gettext in that it shows up in lots of places. That's why I thought it might be reasonable and worthwhile to do.... Fixing the compiler bug is both unlikely and slow. |
As I said, as long as we are looking for exactly "_T", I don't see problems. If not, I would prefer not introducing a line break (which would also "solve" this bug). |
This behavior conforms with the C++03 standard ([lex.string]p3): |
AFAICT this is fixed by Alex's r190804. |
Extended Description
Assume you have a macro defined as follows:
_T(x) L ## x
Where L"A string" makes wchar_t literal
Now when you have code like this:
_T("Some really long string that needs to be split into multiple lines")
clang-format will output:
_T("Some really long string that needs"
" to be split into multiple lines")
On visual studio 2010, this appears to be expanded as:
L"Some really long string that needs" " to be split into multiple lines"
and I get an error:
error C2308: concatenating mismatched strings
The text was updated successfully, but these errors were encountered: