Skip to content

Commit 322f02a

Browse files
committed
[driver] Use if/else instead of ternary, to please VS2017.
VS2017 seems to have problems with ternaries where the two branches are given as std::move() (see https://stackoverflow.com/questions/53374182) and the compiler was given a warning C4172 "returning address of local or temporary". Switching the ternary operator into a `if/else` works correctly for VS2017 and should work for other compilers too, without changing the meaning (as far as I see). This was causing the Windows VS2017 CI to fail compiling the stdlib. When bisecting, the problem was reduced to the changes in #35034. In a debugger I managed to see the problem being a heap corruption. With all the moves I was suspicious that something was being used while destroyed, but the code was correct. While recompiling the compiler warning gave me the clue.
1 parent 3dff622 commit 322f02a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/Driver/Compilation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,11 @@ namespace driver {
18021802

18031803
fine_grained_dependencies::ModuleDepGraph &&
18041804
takeFineGrainedDepGraph(const bool forRanges) && {
1805-
return forRanges ? std::move(FineGrainedDepGraphForRanges)
1806-
: std::move(FineGrainedDepGraph);
1805+
if (forRanges) {
1806+
return std::move(FineGrainedDepGraphForRanges);
1807+
} else {
1808+
return std::move(FineGrainedDepGraph);
1809+
}
18071810
}
18081811
};
18091812
} // namespace driver

0 commit comments

Comments
 (0)