title: Segmentation fault in copy assignment operator
body: <p>I've been having problems with a segmentation fault that is driving me crazy. Basically I have a class Expression that contains an Expression_Tree. I'm trying to set my variable current_expression equal to a new expression object from an infix string.</p>
  
  <p>Try to set variable to an expression:</p>
  
  <pre><code>try{
      current_expression_ = make_expression(infix); //Segmentation fault here.
  }catch(Expression_Error ee){
      cerr &lt;&lt; ee.what() &lt;&lt; endl;
  } 
  </code></pre>
  
  <p>make_expression takes an infix string, generates a postfix, then generates a Expression_Tree, creates an Expression object with the expression tree and returns it.</p>
  
  <pre><code>Expression make_expression(const string&amp; infix)
  {
      string postfix = make_postfix(infix);
      cout &lt;&lt; "Made postfix" &lt;&lt; endl;
      Expression_Tree* et= make_expression_tree(postfix);
      cout &lt;&lt; "Made Expression_Tree" &lt;&lt; endl;
      cout &lt;&lt; "Returning Expression" &lt;&lt; endl;
      return Expression{et};
     }
  }
  </code></pre>
  
  <p>My copy assign operator and swap functions looks like this:</p>
  
  <pre><code>Expression Expression::operator=(const Expression&amp; e) &amp;{
    cout &lt;&lt; "In copy assign operator" &lt;&lt; endl;
    Expression{e}.swap(*this);
    cout &lt;&lt; "Swapped Expression and this" &lt;&lt; endl;
    return *this;
  }
  void Expression::swap(Expression&amp; rhs){
    cout &lt;&lt; "In swap function" &lt;&lt; endl;
      std::swap(tree, rhs.tree);
  }
  </code></pre>
  
  <p>And my Expression destructor looks like this:</p>
  
  <pre><code>Expression::~Expression(){
    cout &lt;&lt; "In Expression destructor" &lt;&lt; endl;
    delete tree;
  }
  </code></pre>
  
  <p>Copy constructor</p>
  
  <pre><code>Expression::Expression(Expression_Tree* input_tree)
    :tree(input_tree){}
  </code></pre>
  
  <p>Output when running the program:</p>
  
  <pre><code>&gt;&gt; u
  x=1+1
  Made postfix
  Made Expression_Tree
  Returning Expression
  In copy assign operator
  In swap function
  In Expression destructor
  Swapped Expression and this
  In Expression destructor
  In Expression destructor
  Segmentation fault
  </code></pre>
  
  <p>It seems like the tree is trying to be destroyed two times, so when the destructor gets called the second time it's allready deleated and gives an segmentation fault. Any help in pointing out the problem or any advice is appriciated!</p>