[Bug libstdc++/78713] [missed optimization] gcc doesn't use clobbers to optimize constructors

avi@cloudius-systems.com gcc-bugzilla@gcc.gnu.org
Fri Dec 9 12:59:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78713

--- Comment #2 from Avi Kivity <avi@cloudius-systems.com> ---
I think the middle-end knows it is safe to write to *this, because this is
happening in a constructor, so all of the object's memory is known clobbered.

Similarly, if the assignment operator is written as


  optional& optional::operator=(optional&& x) noexcept(...) {
    if (this != &x) {
      this->~optional();
      new (this) optional(std::move(x));
    }
  }

then it has the same information during assignment.

Implementation in the middle end is more useful, because then you don't need
very careful coding of the type, or to depend on is_trivial_foo<>; more user
code will benefit.


More information about the Gcc-bugs mailing list