Author: hokein Date: Mon Oct 17 10:26:34 2016 New Revision: 284391 URL: http://llvm.org/viewvc/llvm-project?rev=284391&view=rev Log: [clang-move] Fix generating illegal header guard.
The filepath might contain some characters (i.e. '@') which are not illegal in c identifiers. This patch changes all non-alphanumeric characters to '_'. Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=284391&r1=284390&r2=284391&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original) +++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Mon Oct 17 10:26:34 2016 @@ -233,10 +233,10 @@ createInsertedReplacements(const std::ve std::string NewCode; std::string GuardName(FileName); if (IsHeader) { - std::replace(GuardName.begin(), GuardName.end(), '/', '_'); - std::replace(GuardName.begin(), GuardName.end(), '.', '_'); - std::replace(GuardName.begin(), GuardName.end(), '-', '_'); - + for (size_t i = 0; i < GuardName.size(); ++i) { + if (!isAlphanumeric(GuardName[i])) + GuardName[i] = '_'; + } GuardName = StringRef(GuardName).upper(); NewCode += "#ifndef " + GuardName + "\n"; NewCode += "#define " + GuardName + "\n"; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits