diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-12-16 13:37:17 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-12-16 14:33:26 +0000 |
commit | 4e42f6ebf483452015c3d102c6ac45741fceb87b (patch) | |
tree | 254d33a20c5edd31118eca2f64b70f549ec2f7a6 | |
parent | 96d9670e88333d8896a5d2f2bb0403c1e2ad19ab (diff) | |
download | gcc-4e42f6ebf483452015c3d102c6ac45741fceb87b.zip gcc-4e42f6ebf483452015c3d102c6ac45741fceb87b.tar.gz gcc-4e42f6ebf483452015c3d102c6ac45741fceb87b.tar.bz2 |
libcody: Fix build for older GCC versions
Before CWG DR 1955 the controlling expression for an #elif must be
syntactically correct, meaning this won't compile with C++11 compilers
such as gcc 4.8:
The solution is to define __has_include(X) as 0 for compilers that don't
support it.
The second problem is that when <source_location> is found, it is used
without the std:: qualification.
libcody/ChangeLog:
* internal.hh: Define fallback macros for __has_builtin and
__has_include. Use __has_builtin for __builtin_FILE and
__builtin_LINE. Define alias for std::source_location.
-rw-r--r-- | libcody/internal.hh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libcody/internal.hh b/libcody/internal.hh index d744b56..87673f5 100644 --- a/libcody/internal.hh +++ b/libcody/internal.hh @@ -4,14 +4,23 @@ #include "cody.hh" +#ifndef __has_builtin +#define __has_builtin(X) 0 +#endif +#ifndef __has_include +#define __has_include(X) 0 +#endif + // C++ -#if __GNUC__ >= 10 +#if __has_builtin(__builtin_FILE) && __has_builtin(__builtin_LINE) #define CODY_LOC_BUILTIN 1 -#elif !defined (__has_include) #elif __has_include (<source_location>) #include <source_location> +#ifdef __cpp_lib_source_location #define CODY_LOC_SOURCE 1 #endif +#endif + // C #include <cstdio> @@ -44,6 +53,8 @@ public: } #if !CODY_LOC_BUILTIN && CODY_LOC_SOURCE + using source_location = std::source_location; + constexpr Location (source_location loc = source_location::current ()) : Location (loc.file (), loc.line ()) { |