title: Why is C++'s void type only half-heartedly a unit type?
body: <p>C++'s <code>void</code> type is not uninhabited. The problem is that while it has precisely one inhabitant, very much like the <code>Unit</code> type (a.k.a. <code>()</code>) in ML-like languages, that inhabitant cannot be named or passed around as an ordinary value. For example, the following code fails to compile:</p>
  
  <pre><code>void foo(void a) { return; }
  void bar() { foo(foo()); }
  </code></pre>
  
  <p>whereas equivalent (say) Rust code would compile just fine:</p>
  
  <pre><code>fn foo(a : ()) { return; }
  fn bar() { foo(foo(())); }
  </code></pre>
  
  <p>In effect, <code>void</code> is like a <code>unit</code> type, but only half-heartedly so. Why is this the case?</p>
  
  <p>Does the C++ standard explicitly state that one cannot create values of type <code>void</code>? If yes, what is the rationale behind this decision? If not, why does the code above not compile?</p>
  
  <p>If it is some backwards-compatibility related reason, please give a code example.</p>
  
  <p>To be clear, I'm not looking for work-arounds to the problem (e.g. using an empty struct/class). I want to know the historical reason(s) behind the status quo.</p>
  
  <p>EDIT: I've changed the syntax in the code examples slightly to make it clear that I'm not trying to hijack existing syntax like <code>void foo(void)</code> (consequently, some comments may be out of date). The primary motivation behind the question is "why is the type system not like X" and <em>not</em> "why does this bit of syntax not behave as I'd like it to". Please keep this point in mind if you're writing an answer talking about breaking backwards compatibility.</p>