public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libcody: Fix build for older GCC versions
@ 2020-12-16 13:05 Jonathan Wakely
  2020-12-16 14:07 ` Nathan Sidwell
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2020-12-16 13:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathan Sidwell

[-- Attachment #1: Type: text/plain, Size: 721 bytes --]

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.

Built on GNu/Linux using both gcc-11 and gcc-4.8, and also by hacking
it so that __builtin_FILE and __builtin_LINE aren't found, and
<source_location> gets used.

OK for trunk?



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1687 bytes --]

commit 2c0f7be4ceb175714ede9ad7cbf364314bec2f4a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Dec 16 12:58:14 2020

    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.

diff --git a/libcody/internal.hh b/libcody/internal.hh
index d744b564cda..87673f56657 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 ())
   {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libcody: Fix build for older GCC versions
  2020-12-16 13:05 [PATCH] libcody: Fix build for older GCC versions Jonathan Wakely
@ 2020-12-16 14:07 ` Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2020-12-16 14:07 UTC (permalink / raw)
  To: Jonathan Wakely, gcc-patches

On 12/16/20 8:05 AM, Jonathan Wakely wrote:
> 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.
> 
> Built on GNu/Linux using both gcc-11 and gcc-4.8, and also by hacking
> it so that __builtin_FILE and __builtin_LINE aren't found, and
> <source_location> gets used.
> 
> OK for trunk?

great, thanks!

nathan


-- 
Nathan Sidwell

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-16 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 13:05 [PATCH] libcody: Fix build for older GCC versions Jonathan Wakely
2020-12-16 14:07 ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).