New clang-tidy modernize-nlohmann-json-explicit-conversions check #4610
Replies: 2 comments 3 replies
-
Wow, this is awesome! I will give it a try soon. At first glance, I would definitely love to mention this in the documentation for implicit conversions (and also on https://json.nlohmann.me/integration/migration_guide). And yes, please try to submit this upstream! In any case, your project is an excellent starting point for integrating other changes that would make the transition to the next major version as smooth as possible. |
Beta Was this translation helpful? Give feedback.
-
I proposed an improved version of the check for inclusion in clang-tidy in llvm/llvm-project#126425 and it seems that they don't want to add checks for third-party libraries. I'm going to try to turn the check into a plugin instead. |
Beta Was this translation helpful? Give feedback.
-
I've written a somewhat rudimentary clang-tidy check that will automatically convert existing implicit conversions to explicit conversions. In other words, it turns:
into
by knowing what the target type is for the implicit conversion and turning that into an explicit call to the
get
method with that type as the template parameter. Further examples can be found in the tests for the check.I've used this check to replace 220 of 221 implicit conversions in our code. It was incapable of recognising an implicit conversion used to construct
std::optional
and left it alone. Even if it can't do the whole job, I think it's better than nothing.Using this check may ease the path towards removing these implicit conversions in a future version of the library.
I raise it here in case:
you can see any flaws in it or suggest more test cases.
you think it's worth of a link from
mkdocs/docs/api/macros/json_use_implicit_conversions.md
.I haven't tried to submit it to the upstream llvm-project. I'm not sure whether they'll accept checks for third-party (non-Google) libraries. If the response here is favourable then I can try.
Beta Was this translation helpful? Give feedback.
All reactions