[PATCH] D15411: [clang-tidy] Check for suspicious string assignments.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 10 08:52:39 PST 2015


alexfh added inline comments.

================
Comment at: clang-tidy/misc/StringIntegerAssignmentCheck.cpp:45
@@ +44,3 @@
+
+  auto Diag = diag(Loc, "probably missing to_string operation");
+  if (!Loc.isMacroID() && getLangOpts().CPlusPlus11) {
----------------
I'd expand the message with an explanation of what actually happens here. Also it's not clear what the "to_string operation" refers to. And one more thing I missed, is other character types.

So I'd go with something similar to: "an integer is interpreted as a character code when assigning it to a string; if this is intended, cast the integer to '%0'; if you want a string representation, use %select{std::to_string()|std::to_wstring()|appropriate conversion facility}1", where %0 should be substituted with `char`/`wchar_t`/whatever the specific character type is.

(and please add tests for other character types)


http://reviews.llvm.org/D15411





More information about the cfe-commits mailing list