Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor/destructor of optional type called twice #59

Closed
deadem opened this issue Nov 20, 2020 · 1 comment
Closed

Constructor/destructor of optional type called twice #59

deadem opened this issue Nov 20, 2020 · 1 comment

Comments

@deadem
Copy link

deadem commented Nov 20, 2020

Code to reproduce:

#include <https://raw.githubusercontent.com/martinmoene/optional-lite/master/include/nonstd/optional.hpp>
#include <iostream>

struct Type {
  Type(int) {
    std::cout << "construct" << std::endl;
  }
  Type(Type &&) {
    std::cout << "move" << std::endl;
  }
  ~Type() {
    std::cout << "destruct" << std::endl;
  }
};

int main()
{
  nonstd::optional<Type> t(0);

  return t.has_value();
}

Expected:

construct
destruct

Output:

construct
move
destruct
destruct

Live code: https://godbolt.org/z/5T575q (gcc 7.5 vs gcc latest output)

@martinmoene
Copy link
Owner

In release v3.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants