Incompatibility between compilers

clang and gcc (or other c/c++ compilers) sometimes interpret the C++ standard differently. This may result in a piece of code that is compiled with gcc being rejected by clang (and vice versa).

#include <stdio.h>
#include <stdlib.h> 
​
int a;
int b;
​
int *test() {
   if (rand()) {
   	   return &a;
   } else {
   	   return &b;
   }
}
​
​
int main() {
   if (test() < 0) {
       puts("yes");
   } else {
   	   puts("no");
   }
}

For the above code, while gcc can successfully compile the code, clang fails and will emit the following error.

main.cpp:17:15: error: invalid operands to binary expression ('int *' and 'nullptr_t')
   if (test() < nullptr) {
       ~~~~~~ ^ ~~~~~~~
1 error generated.