title: MinGW-w64 pthread_cleanup_pop() error
body: <p>when compiling a C++ program which contains a "call" to the <code>pthread_cleanup_pop(E)</code> macro, the following error is thrown by g++:</p>
  
  <pre><code>error: second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
  </code></pre>
  
  <p>Now, the apparent problem here is that the macro above expands to
  <code>(*pthread_getclean() = _pthread_cup.next, (E?_pthread_cup.func((pthread_once_t *)_pthread_cup.arg):0));}</code> where the second expression is a call to a function returning void, but the third expression is simply 0.</p>
  
  <p>Althoug I get the basic issue here, I really don't see why the warning occurs in this particular use, as the "result" of the condition is not assigned to anything.</p>
  
  <p>For the record: I compiled the C++ program using MinGW-w64 3.3.0 (GCC 4.9.2) both with and without -std=c++98. In both cases, the error occurs. If I compile the same code as a C program (both with or without -std=c99), there is no error.</p>
  
  <p>Does anyone know how I could get rid of that error in C++, other than by editing pthread.h?</p>
  
  <p>Many thanks in advance!</p>
  
  <p>EDIT: Here is some example code for reference:</p>
  
  <pre><code>#include &lt;pthread.h&gt;
  
  static int cancelled = 0;
  
  static void test_thread_cleanup(void *_arg){
      cancelled = 1;
  }
  
  static void* test_thread(void *_arg){
      pthread_cleanup_push(&amp;test_thread_cleanup, NULL);   // push cleanup handler on stack
      while (1){                                          // never left unless cancelled via pthread_cancel() from main()
          pthread_testcancel();                           // just test for pthread_cancel() having been called
      }
      pthread_cleanup_pop(1);                             // pop cleanup handler from stack
  
      return NULL;                                        // actually never reached
  }
  
  int main(void){
      pthread_t       th;
  
      pthread_create(&amp;th, NULL, &amp;test_thread, NULL);
      pthread_cancel(th);
      pthread_join(th, NULL);
  
      return cancelled;
  }
  </code></pre>