title: Why does the C++ standard require compilers to ignore calls to convertion operators for base types?
body: <p>Take the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct Base {
      char x = 'b';  
  };
  
  struct Derived : Base {
      operator Base() { return Base { 'a' }; }
  };
  
  int main() {
      Derived derived;
      auto base = static_cast&lt;Base&gt;(derived);
  
      std::cout &lt;&lt; "BASE -&gt; " &lt;&lt; base.x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Under both g++ and clang++, this produces:</p>
  
  <pre><code>BASE -&gt; b
  </code></pre>
  
  <p>I was expecting the following:</p>
  
  <pre><code>BASE -&gt; a
  </code></pre>
  
  <p>Why? Because why I read this code, I see a conversion operator inside of <code>Derived</code> that returns an instance of <code>Base</code> containing <code>'a'</code>.</p>
  
  <p>clang++ did me the courtesy of emitting a warning:</p>
  
  <pre><code>main.cpp:9:5: warning: conversion function converting 'Derived' to its base class 'Base' will never be used
      operator Base() { return Base { 'a' }; }
  </code></pre>
  
  <p>Researching this warning, I found that this was by design (paraphrased for clarity):</p>
  
  <blockquote>
    <p><a href="http://eel.is/c++draft/class.conv.fct#1" rel="noreferrer">class.conv.fct</a></p>
    
    <p>The type of the conversion function ([dcl.fct]) is “function taking no parameter returning conversion-type-id”. A conversion function is never used to convert a (possibly cv-qualified) object [...] to a (possibly cv-qualified) base class of that type (or a reference to it) [...].</p>
  </blockquote>
  
  <p>So it would seem that both compilers are doing the right thing here.
  My question is, why does the standard require this behaviour?</p>