Add <stdlib.h> includes for clang++/libc++ on Ubuntu
authorDan Willemsen <dwillemsen@google.com>
Thu, 21 Apr 2016 00:29:00 +0000 (17:29 -0700)
committerDan Willemsen <dwillemsen@google.com>
Thu, 21 Apr 2016 01:24:10 +0000 (18:24 -0700)
There are a number of stdlib.h uses in these files without including
stdlib.h:

 hash_collision_bench.cc: rand, RAND_MAX, srand
 manifest_parser_perftest.cc: system, exit
 ninja_test.cc: EXIT_SUCCESS, EXIT_FAILURE
 test.cc: getenv, mkdtemp, system

This works on a Ubuntu g++/libstdc++ build, as the <algorithm> header
pulls in stdlib.h, and on a OSX clang++/libc++ build the <map> and
<string> headers pull in stdlib.h. But a Ubuntu clang++/libc++ build
does not pull in stdlib.h with any of these other headers.

 $ apt-get install clang-3.6 libc++-dev
 $ CXX=clang++-3.6 CFLAGS=-stdlib=libc++ LDFLAGS=-stdlib=libc++ \
   ./configure.py
 $ ninja ninja_test hash_collision_bench manifest_parser_perftest

This was originally discovered using the host toolchain provided with
Android, but the Ubuntu version is much easier to reproduce.

src/hash_collision_bench.cc
src/manifest_parser_perftest.cc
src/ninja_test.cc
src/test.cc

index 5be0531..ff947dc 100644 (file)
@@ -17,6 +17,7 @@
 #include <algorithm>
 using namespace std;
 
+#include <stdlib.h>
 #include <time.h>
 
 int random(int low, int high) {
index 572e2d5..60c2054 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #ifdef _WIN32
index 11087b6..d642c5c 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #ifdef _WIN32
 #include "getopt.h"
index 53bfc48..51882f0 100644 (file)
@@ -21,6 +21,7 @@
 #include <algorithm>
 
 #include <errno.h>
+#include <stdlib.h>
 #ifdef _WIN32
 #include <windows.h>
 #else