I was testing a C++ project of mine with older versions of GCC, and mistakingly used the following command: $ ./configure CXX=gcc-4.7
Autoconf didn't spot any problem: > checking whether the C++ compiler works... yes But of course gcc-4.7 doesn't know how to link a C++ program, so my build failed. The attached patch fixes this problem by changing the C++ null program into: int main() { (void) new int; return 0; } Any C++ compiler, even an ancient one, should be able to pass that test, but C compilers will fail. In GCC's case, the program will compile but the link will fail because libc doesn't contain an 'operator new'.
Index: autoconf-2.69/lib/autoconf/c.m4 =================================================================== --- autoconf-2.69.orig/lib/autoconf/c.m4 2012-01-21 14:46:39.000000000 +0100 +++ autoconf-2.69/lib/autoconf/c.m4 2014-02-05 10:06:25.172408390 +0100 @@ -247,6 +247,14 @@ ]) +# _AC_LANG_NULL_PROGRAM(C++) +# -------------------------- +# To distinguish a C++ compiler from a C compiler, test if we can compile +# and link a program with a C++-specific construct. +m4_define([_AC_LANG_NULL_PROGRAM(C++)], +[AC_LANG_PROGRAM([], [(void) new int;])]) + + # AC_LANG_CPLUSPLUS # ----------------- AU_DEFUN([AC_LANG_CPLUSPLUS], [AC_LANG(C++)])