preprocessor: Teach traditional about has_include [PR95889]
authorTiziano Müller <tiziano.mueller@chem.uzh.ch>
Wed, 29 Jul 2020 14:28:23 +0000 (07:28 -0700)
committerNathan Sidwell <nathan@acm.org>
Wed, 29 Jul 2020 14:47:21 +0000 (07:47 -0700)
Traditional cpp (used by fortran) didn;t know about the new
__has_include__ implementation.  Hey, since when did traditional cpp
grow __has_include__? That wasn't in knr!

libcpp/
* init.c (builtin_array): Add xref comment.
* traditional.c (fun_like_macro): Add HAS_INCLUDE codes.
gcc/testsuite/
* c-c++-common/cpp/has-include-1-traditional.c: New.

gcc/testsuite/c-c++-common/cpp/has-include-1-traditional.c [new file with mode: 0644]
libcpp/init.c
libcpp/traditional.c

diff --git a/gcc/testsuite/c-c++-common/cpp/has-include-1-traditional.c b/gcc/testsuite/c-c++-common/cpp/has-include-1-traditional.c
new file mode 100644 (file)
index 0000000..b0acdbe
--- /dev/null
@@ -0,0 +1,38 @@
+/* { dg-do preprocess { target c } } */
+/* { dg-options "-traditional-cpp" } */
+
+#if __has_include ("stdlib.h")
+#else
+#error error 1
+#endif
+#if __has_include (<stdlib.h>)
+#else
+#error error 2
+#endif
+#if !__has_include ("stdlib.h")
+#error error 3
+#elif !__has_include (<stdlib.h>)
+#error error 4
+#endif
+#if __has_include ("stdlib.h") && __has_include (<stdlib.h>)
+#else
+#error error 5
+#endif
+#if !defined(__has_include)
+#error error 6
+#endif
+#ifndef __has_include
+#error error 7
+#endif
+#ifdef __has_include
+#else
+#error error 8
+#endif
+#define m1 __has_include("stdlib.h")
+#define m2 <stdlib.h>
+#if !m1
+#error error 9
+#endif
+#if !__has_include (m2)
+#error error 13
+#endif
index f9f1fb204f0377a143de721f7349269468ac6e09..aba5854d357b6b76f05b4abebb15fe16b2426aef 100644 (file)
@@ -400,6 +400,9 @@ static const struct builtin_macro builtin_array[] =
   B("__LINE__",                 BT_SPECLINE,      true),
   B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true),
   B("__COUNTER__",      BT_COUNTER,       true),
+  /* Make sure to update the list of built-in
+     function-like macros in traditional.c:
+     fun_like_macro() when adding more following */
   B("__has_attribute",  BT_HAS_ATTRIBUTE, true),
   B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true),
   B("__has_builtin",    BT_HAS_BUILTIN,   true),
index 77adb3bf595fe5f358528b192f8e8ca5d78ee5b2..b087072c9b4ced7a85a15dc53110d0037ce03dad 100644 (file)
@@ -330,7 +330,9 @@ fun_like_macro (cpp_hashnode *node)
 {
   if (cpp_builtin_macro_p (node))
     return (node->value.builtin == BT_HAS_ATTRIBUTE
-           || node->value.builtin == BT_HAS_BUILTIN);
+           || node->value.builtin == BT_HAS_BUILTIN
+           || node->value.builtin == BT_HAS_INCLUDE
+           || node->value.builtin == BT_HAS_INCLUDE_NEXT);
   return node->value.macro->fun_like;
 }