title: Does const pointer-to-member default to pointing to an int?
body: <p>While playing with pointers-to-member I encountered a behaviour that seems slightly inconsistent and somewhat counterintuitive to me. Consider the following dummy structure:</p>
  <pre><code>struct foo {
      int x;
      double d;
  };
  </code></pre>
  <p>and the following <code>main()</code>:</p>
  <pre><code>int main() {
      int foo::* ptr = &amp;foo::x;
      double foo::* ptr2 = &amp;foo::d;
  }
  </code></pre>
  <p>Here we have nothing unusual - two pointers to <code>const</code> members. The code compiles fine.</p>
  <p>What caught my attention is that when we add <code>const</code>, the situation changes a little bit. Consider the following code:</p>
  <pre><code>int main() {
      // no int or double after const
      const foo::* ptr = &amp;foo::x;
  }
  </code></pre>
  <p>The code compiles fine on <strong>GCC 8.2.0</strong><sup>1</sup>. Notice that I did not specify to what data type the pointer will point.</p>
  <p>However, this code:</p>
  <pre><code>int main() {
      // notice the only change - &quot;d&quot; instead of &quot;x&quot;
      const foo::* ptr = &amp;foo::d;
  }
  </code></pre>
  <p>fails to compile with the following error:</p>
  <blockquote>
  <p>error: cannot convert '<code>double foo::*</code>' to '<code>const int foo::*</code>' in initialization <code>const foo::* ptr = &amp;foo::d;</code></p>
  </blockquote>
  <p>Which is interesting - it suggests that, by default, a <code>const</code> pointer-to-member is implicitely declared to point to some <code>int</code> member. Is this correct, standard behaviour?</p>
  <p>It's worth noting that if we drop the <code>const</code>, both of these lines produce errors:</p>
  <pre><code>int main() {
      foo::* ptr1 = &amp;foo::x;
      foo::* ptr2 = &amp;foo::d;
  }
  </code></pre>
  <p>in the forms of:</p>
  <blockquote>
  <p>error: expected unqualified-id before '<code>*</code>' token</p>
  <p>error: '<code>ptr1</code>' | '<code>ptr2</code>' was not declared in this scope</p>
  </blockquote>
  <p>So the question is - <strong>does the standard specify that <code>const</code> pointer-to-member implicitly points to <code>int</code> if we do not specify otherwise, or is it a non-standard behaviour?</strong> (either a GCC extension or GCC bug).</p>
  <hr />
  <p><sup>1</sup>EDIT: I am using GCC from MinGW - <a href="https://nuwen.net/mingw.html#Download" rel="nofollow noreferrer">this</a> particular build.</p>