title: Compiling with -std=c++11 on Cygwin hides available system calls
body: <p>I was investigating porting some code from older C++ to a more modern C++ version (e.g. C++ 11 or higher). And then I noticed some networking code not compiling when I added the compiler flag <code>-std=c++11</code></p>
  
  <p>Simplest MVCE example.  I'm on the latest Cygwin (literally installed today). <code>g++ --version</code> indicates version 7.3.0.</p>
  
  <p>Take the following source file stripped down to almost nothing, but enough to show the issue I am about to explain.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netdb.h&gt;
  
  int some_networking_code()
  {
     addrinfo* addr = NULL;
     int flags = AI_NUMERICHOST;
     return 0;
  }
  </code></pre>
  
  <p>On a fresh install of Cygwin, the following command works just fine:</p>
  
  <pre><code>g++ foo.cpp -c
  </code></pre>
  
  <p>But now switch to compiling with C++11.</p>
  
  <pre><code>g++ foo.cpp -c -std=c++11
  </code></pre>
  
  <p>And the resulting compiler output is:</p>
  
  <pre><code>foo.cpp: In function ‘int some_networking_code()’:
  foo.cpp:8:4: error: ‘addrinfo’ was not declared in this scope
      addrinfo* addr = NULL;
      ^~~~~~~~
  foo.cpp:8:4: note: suggested alternative: ‘addr_t’
      addrinfo* addr = NULL;
      ^~~~~~~~
      addr_t
  foo.cpp:8:14: error: ‘addr’ was not declared in this scope
      addrinfo* addr = NULL;
                ^~~~
  foo.cpp:8:14: note: suggested alternative: ‘addr_t’
      addrinfo* addr = NULL;
                ^~~~
                addr_t
  foo.cpp:9:16: error: ‘AI_NUMERICHOST’ was not declared in this scope
      int flags = AI_NUMERICHOST;
                  ^~~~~~~~~~~~~~
  </code></pre>
  
  <p>Debugging this, I take a peek at <code>/usr/include/netdb.h</code> and I see that the definition for <code>addrinfo</code> expects a macro called <strong>__POSIX_VISIBLE</strong> to be greater than or equal to <code>200112</code>.  There definition for AI_NUMERICONLY is wrapped within a similar block.</p>
  
  <pre><code>#if __POSIX_VISIBLE &gt;= 200112 &amp;&amp; !defined(__INSIDE_CYGWIN_NET__)
  struct addrinfo {
    int             ai_flags;             /* input flags */
    … &lt;deleted for brevity&gt;
  #endif
  </code></pre>
  
  <p>Using the <code>-dM -E</code> switches, we can ask the compiler for what macros it's pulling in and filter to the POSIX_VISIBLE</p>
  
  <pre><code>$ g++ foo.cpp -c -dM -E | grep POSIX_VIS
  #define __POSIX_VISIBLE 200809
  </code></pre>
  
  <p>Ok, that looks correct for traditional C++.  Let's inspect that for C++11 building:</p>
  
  <pre><code>$ g++ foo.cpp -c -std=c++11 -dM -E | grep POSIX_VIS
  #define __POSIX_VISIBLE 0
  </code></pre>
  
  <p><code>__POSIX_VISIBLE</code> is defined to be 0.  And that explains why we have the errors above.</p>
  
  <p>It appears that <code>POSIX_VISIBLE</code> is getting defined by the header file at <code>/usr/include/sys/features.h</code> based on other defined macros.  But that's where I start to get confused.</p>
  
  <p>Is this a bug in the Cygwin distro or its header files?  The way the compiler was built?  Or something else?  What's the appropriate workaround that won't impact building on Linux, Mac, BSD, and everywhere else?</p>