Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
assert(ArgsCstrBuff[ArgsCstrBuffLen - 1] == '\0');
auto Arg0 = std::string(ArgsCstrBuff);
buffer_offset = Arg0.size() + 1;
auto ArgsCppStr =
std::string(ArgsCstrBuff + buffer_offset, ArgsCstrBuffLen - 1);
auto ArgsCppStr = std::string(ArgsCstrBuff + buffer_offset,
ArgsCstrBuffLen - buffer_offset);
auto i = 0;
while (i != std::string::npos) {
i = ArgsCppStr.find('\0', i + 1);
if (i != std::string::npos)
ArgsCppStr.replace(i, i + 1, " ");
ArgsCppStr.replace(i, 1, " ");
Comment on lines +493 to +499
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, re-reading the reference about std::string::npos, I think I may have misunderstood something about it.

Why is it correct at all as part of a conditional expression like a while or if? It only takes on its magic "until the end of the string" meaning when used as an argument to std::string's functions, doesn't it? Which the control-flow expressions are not invocations of.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cplusplus.com/reference/string/string/find/

Return Value
The position of the first character of the first match.
If no matches were found, the function returns string::npos.

npos isn't magic, it's in practice just a way to say -1. find() returns npos if something isn't found, and at that point we don't take this if / exit the loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay!

}
Options.MCOptions.Argv0 = Arg0;
Options.MCOptions.CommandlineArgs = ArgsCppStr;
Expand Down
Loading