This patch changes the check for _T to detect TMarcos with a more generic check.
This makes it possible to format wxWidgets projects (where wxT is used a lot) correctly.
Patch by Teodor Petrov
Differential D44765
PR36643 Make clang-format support more generic TMarcos obfuscated on Mar 21 2018, 5:31 PM. Authored by
Details
Diff Detail Event TimelineComment Actions We can't just treat anything("....") like the _T macro. There should be a whitelist configurable with an option. By default only _T should be handled. Comment Actions A generic (or at least extandable) approach to specifying macro behaviors was introduced here: https://reviews.llvm.org/D33440 But this change seem to be on hold, as a configuration based on providing "macro definitions" seem to be preferable and kind-of in the pipe, though with no defined timeline... Comment Actions I believe, that patch solves a significantly different problem and it won't make it much easier to implement correct handling of _T(x)-like macros (which expand to either x or L ## x depending on some other macro and thus have to be repeated for each fragment of the string literal after splitting). The most extensible solution I see is to make the list of _T-like macro spellings configurable via an option. Comment Actions You are right, I did not mean it would help with the handling of these macros; but it may be related on the configuration-side of things : adding an option for listing these macros may hit the same limitation, and the same mean of storing (in the code) the list of these macros may be used. Comment Actions What cases could break with this version of the patch? Comment Actions It is fine to split _T("veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery loooooooooooooooooooooooooooong striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing") as _T("veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery ") _T("loooooooooooooooooooooooooooong ") _T("striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing") and it's incorrect to split it like this: _T("veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery " "loooooooooooooooooooooooooooong " "striiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiing") since only the first string literal will get the L prefix in case when _T(x) is defined as L ## x. The same is valid for wxT() as I understand. However, it's wrong to do so for any function or any macro which uses its argument in any way different from that of _T. E.g. strlen("aaa bbb") is not the same as strlen("aaa ") strlen("bbb")
I'd say this should be an option. Comment Actions Thank you! One more comment from me and I'll leave the rest of the review to Krasimir, who has a better idea of how the configuration options should be named etc.
Comment Actions I don't have preferences over names, but I agree with Alex that the option should have more detailed description.
|
We don't strictly need this new field. We could do as in the old implementation and check if the string prefix is from a T macro in ContinuationIndenter.