Skip to content

Commit 2d1de30

Browse files
committed
Keep string alive
1 parent e3b4b1e commit 2d1de30

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ llvm::json::Object ReadJson(const fs::path &path) {
323323
}
324324

325325
unsigned SinceStandard(const fs::path &src_path) {
326-
llvm::StringRef stem = src_path.stem().string();
326+
auto stem_string = src_path.stem().string();
327+
llvm::StringRef stem = stem_string;
327328
unsigned standard = 11;
328329
if (stem.consume_front("src_cxx") && stem.getAsInteger(10, standard)) {
329330
llvm::errs() << "ERROR: unexpected rule file " << src_path.string() << '\n';

‎cpp2rust/rule_preprocessing/cpp_rule_preprocessor.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,10 @@ int main(int argc, char *argv[]) {
11341134
for (const auto &path : paths) {
11351135
llvm::errs() << "Preprocessing " << path.string() << '\n';
11361136
llvm::SmallVector<llvm::StringRef, 4> file_flags(cxx_flags);
1137+
auto stem = path.stem().string();
11371138
std::string standard_flag;
1138-
if (llvm::StringRef stem = path.stem().string();
1139-
stem.consume_front("src_cxx")) {
1140-
standard_flag = "-std=c++" + stem.str();
1139+
if (llvm::StringRef standard = stem; standard.consume_front("src_cxx")) {
1140+
standard_flag = "-std=c++" + standard.str();
11411141
file_flags.push_back(standard_flag);
11421142
}
11431143
llvm::json::Object file_root;

0 commit comments

Comments
 (0)