From 69860628a7d543ec8cafa6bee65ad44801597e30 Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Fri, 1 Apr 2016 02:26:02 -0700 Subject: [PATCH] Better detection of stdlibc++/libc++ and C++11 Summary:public 1. Make detection of libc++/stdlibc++ headers more robust 2. Turn on c++11 only for newer versions of stdlibc++ Reviewed By: jvillard Differential Revision: D3121187 fb-gh-sync-id: c2e5be5 fbshipit-source-id: c2e5be5 --- .../cpp/include/infer_model/portability.h | 25 ++++++++++++++++--- infer/models/cpp/include/memory | 6 +++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/infer/models/cpp/include/infer_model/portability.h b/infer/models/cpp/include/infer_model/portability.h index aa3695fb0..6af8a4cd9 100644 --- a/infer/models/cpp/include/infer_model/portability.h +++ b/infer/models/cpp/include/infer_model/portability.h @@ -8,12 +8,29 @@ */ #pragma once -// TODO set it in configure script instead -// This is hacky attempt to follow what folly does +// This is a hacky attempt to follow what folly does // https://github.com/facebook/folly/blob/b1eb6819f3ffe6b645f39d505ca8ace3116b7873/folly/configure.ac#L232 -#if !defined(INFER_USE_LIBCPP) && defined(__APPLE__) +// Depending whether the project is compiled with libc++ or stdlibc++, include their +// internal config headers to get information about versions +#if __has_include(<__config>) // defines _LIBCPP_VERSION +#include <__config> +#elif __has_include() // defines __GLIBCXX__ +#include +#endif + +// Figure out whether the library really supports c++11 standard +#if __cplusplus >= 201103L +#if __GLIBCXX__ >= 20130531 +// C++11 is really supported from gcc 4.8.1 onward. +#define INFER_CPP11_ON 1 +#elif defined _LIBCPP_VERSION // for now assume libc++ always supported c++11 +#define INFER_CPP11_ON 1 +#endif +#endif // __cplusplus >= 201103L + +#if !defined(INFER_USE_LIBCPP) && defined(_LIBCPP_VERSION) #define INFER_USE_LIBCPP 1 -#elif defined(FOLLY_USE_LIBCPP) +#elif defined(FOLLY_USE_LIBCPP) // follow folly configuration if it's available #define INFER_USE_LIBCPP 1 #endif diff --git a/infer/models/cpp/include/memory b/infer/models/cpp/include/memory index 9182434a0..928659fa5 100644 --- a/infer/models/cpp/include/memory +++ b/infer/models/cpp/include/memory @@ -1,5 +1,7 @@ -#if __cplusplus >= 201103L +#include + +#ifdef INFER_CPP11_ON #include #include_next @@ -8,7 +10,7 @@ #include #include -#else // __cplusplus < 201103L +#else // don't model memory for pre-C++11 code #include_next #endif