title: In what context does the delete operator throw an error?
body: <p>In my implementation of a linked-list, my helper function <code>deleteNode(Node*)</code> that deletes inner class <code>Node</code> instances is throwing a runtime error, by "triggering a breakpoint" in the Local Windows Debugger in VS 2015. I am being careful to match my <code>new</code> and <code>delete</code> operators. Does scope/reference play a role that I don't realize?</p>
  
  <p>Even if there is a logic error in <code>clear()</code> and <code>deleteNode()</code> gets passed <code>nullptr</code>, it shouldn't throw an error to delete <code>nullptr</code>, and then assign <code>nullptr</code> to itself right? What is the issue with that delete?</p>
  
  <pre><code>class LinkedList {
  public:
      LinkedList() : head(nullptr) {}
      ~LinkedList() { clear(); }
  
      void push_front() {
          head = createNode(head);
      }
  
      void clear() {
          Node* current_node = head;
          while (current_node != nullptr) {
              Node* next_node = current_node-&gt;next; // buffer
              deleteNode(current_node);
              current_node = next_node;
          }
      }
  
  private:    
      struct Node {
          Node(Node* next)
              : next(next) {}
          Node* next;
      };
      Node* head;
      Node* createNode(Node* next) {
          return new Node(next);
      }
      void deleteNode(Node*&amp; toDelete) {
          delete toDelete; // ***VS 2015 puts breakpoint here***
          toDelete = nullptr;
      }
  };
  
  int main() {
      auto A = LinkedList();
      A.push_front();
      A.clear();
      return 0;
  }
  </code></pre>
  
  <p>I have removed all attributes and methods not relevant to the error. This dummy code still throws the same error.</p>