[libc-commits] [PATCH] D129920: [libc] Trivial implementation of std::optional
Markus Böck via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Jul 21 00:48:00 PDT 2022
zero9178 added inline comments.
================
Comment at: libc/src/__support/CPP/Optional.h:44
+
+ Optional(const Optional &t) : StoredValue(t.value()), InUse(true) {}
+
----------------
This copy constructor causes undefined behaviour in the case that `t` is not does not have a value. Shouldn't this be conditionally copying `t.value()` into `StoredValue` depending on whether `t.has_value()`?
(I am an outsider to the libc part of LLVM, but I am guessing you'll probably also want a copy assignment operator acting similarily)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129920/new/
https://reviews.llvm.org/D129920
More information about the libc-commits
mailing list