aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-01-20 05:39:59 -0800
committerNathan Sidwell <nathan@acm.org>2020-01-20 05:39:59 -0800
commitad1a3914ae8d67c94b0d2428e3f9672e7db491a1 (patch)
tree60f0771d802b20be5b8a827738e48324dcb24d2b /gcc
parente82ba180d6641a1e2bad1ac327234fc1cda658ef (diff)
downloadgcc-ad1a3914ae8d67c94b0d2428e3f9672e7db491a1.zip
gcc-ad1a3914ae8d67c94b0d2428e3f9672e7db491a1.tar.gz
gcc-ad1a3914ae8d67c94b0d2428e3f9672e7db491a1.tar.bz2
[PR 80005] Fix __has_include
__has_include is funky in that it is macro-like from the POV of #ifdef and friends, but lexes its parenthesize argument #include-like. We were failing the second part of that, because we used a forwarding macro to an internal name, and hence always lexed the argument in macro-parameter context. We componded that by not setting the right flag when lexing, so it didn't even know. Mostly users got lucky. This reimplements the handline. 1) Remove the forwarding, but declare object-like macros that expand to themselves. This satisfies the #ifdef requirement 2) Correctly set angled_brackets when lexing the parameter. This tells the lexer (a) <...> is a header name and (b) "..." is too (not a string). 3) Remove the in__has_include lexer state, just tell find_file that that's what's happenning, so it doesn't emit an error. We lose the (undocumented) ability to #undef __has_include. That may well have been an accident of implementation. There are no tests for it. We gain __has_include behaviour for all users of the preprocessors -- not just the C-family ones that defined a forwarding macro. libcpp/ PR preprocessor/80005 * include/cpplib.h (BT_HAS_ATTRIBUTE): Fix comment. * internal.h (struct lexer_state): Delete in__has_include field. (struct spec_nodes): Rename n__has_include{,_next}__ fields. (_cpp_defined_macro_p): New. (_cpp_find_file): Add has_include parm. * directives.c (lex_macro_node): Combine defined, __has_inline{,_next} checking. (do_ifdef, do_ifndef): Use _cpp_defined_macro_p. (_cpp_init_directives): Refactor. * expr.c (parse_defined): Use _cpp_defined_macro_p. (eval_token): Adjust parse_has_include calls. (parse_has_include): Add OP parameter. Reimplement. * files.c (_cpp_find_file): Add HAS_INCLUDE parm. Use it to inhibit error message. (_cpp_stack_include): Adjust _cpp_find_file call. (_cpp_fake_include, _cpp_compare_file_date): Likewise. (open_file_failed): Remove in__has_include check. (_cpp_has_header): Adjust _cpp_find_file call. * identifiers.c (_cpp_init_hashtable): Don't init __has_include{,_next} here ... * init.c (cpp_init_builtins): ... init them here. Define as macros. (cpp_read_main_file): Adjust _cpp_find_file call. * pch.c (cpp_read_state): Adjust __has_include{,_next} access. * traditional.c (_cpp_scan_out_locgical_line): Likewise. gcc/c-family/ PR preprocessor/80005 * c-cppbuiltins.c (c_cpp_builtins): Don't define __has_include{,_next}. gcc/testsuite/ PR preprocessor/80005 * g++.dg/cpp1y/feat-cxx14.C: Adjust. * g++.dg/cpp1z/feat-cxx17.C: Adjust. * g++.dg/cpp2a/feat-cxx2a.C: Adjust. * g++.dg/cpp/pr80005.C: New.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-cppbuiltin.c6
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.dg/cpp/pr80005.C24
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C10
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C10
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C10
7 files changed, 43 insertions, 30 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 09ba2c8..fdddb98 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-20 Nathan Sidwell <nathan@acm.org>
+
+ PR preprocessor/80005
+ * c-cppbuiltins.c (c_cpp_builtins): Don't define __has_include{,_next}.
+
2020-01-18 Iain Sandoe <iain@sandoe.co.uk>
* c-common.c (co_await, co_yield, co_return): New.
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index a630892..70a1205 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -876,12 +876,6 @@ c_cpp_builtins (cpp_reader *pfile)
/* For stddef.h. They require macros defined in c-common.c. */
c_stddef_cpp_builtins ();
- /* Set include test macros for all C/C++ (not for just C++11 etc.)
- The builtins __has_include__ and __has_include_next__ are defined
- in libcpp. */
- cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
- cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
-
if (c_dialect_cxx ())
{
if (flag_weak && SUPPORTS_ONE_ONLY)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a526e32..67d5f2e9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-01-20 Nathan Sidwell <nathan@acm.org>
+
+ PR preprocessor/80005
+ * g++.dg/cpp1y/feat-cxx14.C: Adjust.
+ * g++.dg/cpp1z/feat-cxx17.C: Adjust.
+ * g++.dg/cpp2a/feat-cxx2a.C: Adjust.
+ * g++.dg/cpp/pr80005.C: New.
+
2020-01-20 Mark Eggleston <mark.eggleston@codethink.com>
* gfortran.dg/pr93263_1.f90: Change scan-tree-dump-not to
diff --git a/gcc/testsuite/g++.dg/cpp/pr80005.C b/gcc/testsuite/g++.dg/cpp/pr80005.C
new file mode 100644
index 0000000..cc75261
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/pr80005.C
@@ -0,0 +1,24 @@
+// PR preprocessor/80005
+// { dg-do preprocess }
+
+#undef vector
+#define vector NOPE
+#ifdef __has_include
+
+#if !__has_include (<vector>)
+#error "Header 'vector' could not be found"
+#endif
+#define F(X) __has_include (X)
+#if !F (<vector>)
+#error "Header 'vector' could not be found" // { dg-error "not be found" }
+#endif
+
+#if __has_include ("not an escape! \") // comment
+#endif
+
+#if F ("is an escape \") gibberish ")
+#endif
+
+#else
+#error "No __has_include"
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
index a2a93f4..a78b6a3 100644
--- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
@@ -236,20 +236,14 @@
# error "__has_include"
#endif
-// Quoted complex.h should find at least the bracket version (use operator).
-#if __has_include__ "complex.h"
-#else
-# error "complex.h"
-#endif
-
// Try known bracket header (use operator).
-#if __has_include__(<complex>)
+#if __has_include (<complex>)
#else
# error "<complex>"
#endif
// Define and use a macro to invoke the operator.
-#define sluggo(TXT) __has_include__(TXT)
+#define sluggo(TXT) __has_include(TXT)
#if sluggo(<complex>)
#else
diff --git a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
index 55e56a0..e6f456b 100644
--- a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
+++ b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
@@ -225,20 +225,14 @@
# error "__has_include"
#endif
-// Quoted complex.h should find at least the bracket version (use operator).
-#if __has_include__ "complex.h"
-#else
-# error "complex.h"
-#endif
-
// Try known bracket header (use operator).
-#if __has_include__(<complex>)
+#if __has_include (<complex>)
#else
# error "<complex>"
#endif
// Define and use a macro to invoke the operator.
-#define sluggo(TXT) __has_include__(TXT)
+#define sluggo(TXT) __has_include(TXT)
#if sluggo(<complex>)
#else
diff --git a/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C b/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
index dd15cd6..82fd602 100644
--- a/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
+++ b/gcc/testsuite/g++.dg/cpp2a/feat-cxx2a.C
@@ -224,20 +224,14 @@
# error "__has_include"
#endif
-// Quoted complex.h should find at least the bracket version (use operator).
-#if __has_include__ "complex.h"
-#else
-# error "complex.h"
-#endif
-
// Try known bracket header (use operator).
-#if __has_include__(<complex>)
+#if __has_include (<complex>)
#else
# error "<complex>"
#endif
// Define and use a macro to invoke the operator.
-#define sluggo(TXT) __has_include__(TXT)
+#define sluggo(TXT) __has_include(TXT)
#if sluggo(<complex>)
#else