[libcxx-commits] [PATCH] D91140: [8/N] [libcxx] Fix the preexisting directory_iterator code for windows
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Dec 17 14:17:18 PST 2020
ldionne accepted this revision.
ldionne added inline comments.
This revision is now accepted and ready to land.
================
Comment at: libcxx/src/filesystem/directory_iterator.cpp:121
+ }
+ __stream_ = ::FindFirstFileW((root / "*").c_str(), &__data_);
if (__stream_ == INVALID_HANDLE_VALUE) {
----------------
mstorsjo wrote:
> ldionne wrote:
> > Isn't that a use-after-free? `(root / "*").c_str()` returns a pointer to the internal string held in the temporary object created by `(root / "*")`, unless I'm missing a subtlety here. I don't think the lifetime of objects in an expression used as a function argument is extended automatically.
> I don't know the spec bits exactly that allow this, but I'm fairly sure it's supposed to work. An empirical test: https://godbolt.org/z/za8K46
>
> I'm not too familiar with the C++ spec itself to reference it myself, but https://stackoverflow.com/a/584835/3115956 claims that "12.2 Temporary objects" in the C++ standard covers this, saying that the destructors for such temporaries aren't called until at the end of the full-expression.
Uh, you're right, I guess that's an enormous brain fart on my end. Like they say in the SO answer, expression templates are the obvious use case that make use of this property.
See http://eel.is/c++draft/class.temporary#4 for details.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91140/new/
https://reviews.llvm.org/D91140
More information about the libcxx-commits
mailing list