https://gcc.gnu.org/g:110e51ef0f8b44b00fb5e3c82f1db2fcab2a19e1

commit r14-12937-g110e51ef0f8b44b00fb5e3c82f1db2fcab2a19e1
Author: Jakub Jelinek <[email protected]>
Date:   Sun Oct 11 19:39:20 2026 +0200

    Revert "libcpp: Fix up parsing __has_include outside directive [PR121508]"
    
    This commit wasn't intended to be pushed, it is not suitable for 14 branch.
    
    This reverts commit b8c8ee7caec2c828190472ffec272b4f51f35393.

Diff:
---
 gcc/testsuite/c-c++-common/cpp/pr121508-1.c |  8 --------
 gcc/testsuite/c-c++-common/cpp/pr121508-2.c |  8 --------
 gcc/testsuite/c-c++-common/cpp/pr121508-3.c |  8 --------
 gcc/testsuite/c-c++-common/cpp/pr121508-4.c |  8 --------
 gcc/testsuite/c-c++-common/cpp/pr121508-5.c |  8 --------
 gcc/testsuite/c-c++-common/cpp/pr123339.c   |  9 ---------
 libcpp/directives.cc                        | 29 ++++++++++++++++++++++++-----
 7 files changed, 24 insertions(+), 54 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/cpp/pr121508-1.c 
b/gcc/testsuite/c-c++-common/cpp/pr121508-1.c
deleted file mode 100644
index d02a9dd271e2..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr121508-1.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* PR preprocessor/121508 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_include' used outside of preprocessing directive" "" { 
target *-*-* } .+4 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+3 } */
-/* { dg-error "missing '\\\)' after '__has_include' operand" "" { target *-*-* 
} .+2 } */
-/* { dg-error "expected ',' or ';' at end of input" "" { target *-*-* } .+1 } 
*/
-int i = __has_include(<__int16_t
diff --git a/gcc/testsuite/c-c++-common/cpp/pr121508-2.c 
b/gcc/testsuite/c-c++-common/cpp/pr121508-2.c
deleted file mode 100644
index 884924126bde..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr121508-2.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* PR preprocessor/121508 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_include' used outside of preprocessing directive" "" { 
target *-*-* } .+4 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+3 } */
-/* { dg-error "missing '\\\)' after '__has_include' operand" "" { target *-*-* 
} .+2 } */
-/* { dg-error "expected ',' or ';' at end of input" "" { target *-*-* } .+1 } 
*/
-int i = __has_include(<__int16_t)
diff --git a/gcc/testsuite/c-c++-common/cpp/pr121508-3.c 
b/gcc/testsuite/c-c++-common/cpp/pr121508-3.c
deleted file mode 100644
index 02cbca9b03a0..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr121508-3.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* PR preprocessor/121508 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_embed' used outside of preprocessing directive" "" { 
target *-*-* } .+4 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+3 } */
-/* { dg-error "expected '\\\)'" "" { target *-*-* } .+2 } */
-/* { dg-error "expected ',' or ';' at end of input" "" { target *-*-* } .+1 } 
*/
-int i = __has_embed(<__int16_t
diff --git a/gcc/testsuite/c-c++-common/cpp/pr121508-4.c 
b/gcc/testsuite/c-c++-common/cpp/pr121508-4.c
deleted file mode 100644
index 1c2ee78551a9..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr121508-4.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* PR preprocessor/121508 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_embed' used outside of preprocessing directive" "" { 
target *-*-* } .+4 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+3 } */
-/* { dg-error "expected '\\\)'" "" { target *-*-* } .+2 } */
-/* { dg-error "expected ',' or ';' at end of input" "" { target *-*-* } .+1 } 
*/
-int i = __has_embed(<__int16_t)
diff --git a/gcc/testsuite/c-c++-common/cpp/pr121508-5.c 
b/gcc/testsuite/c-c++-common/cpp/pr121508-5.c
deleted file mode 100644
index f9be0f0444b3..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr121508-5.c
+++ /dev/null
@@ -1,8 +0,0 @@
-/* PR preprocessor/121508 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_embed' used outside of preprocessing directive" "" { 
target *-*-* } .+4 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+3 } */
-/* { dg-error "expected '\\\)'" "" { target *-*-* } .+2 } */
-/* { dg-error "expected ',' or ';' at end of input" "" { target *-*-* } .+1 } 
*/
-int i = __has_embed(<__int16_t + 1 + 2 + 3
diff --git a/gcc/testsuite/c-c++-common/cpp/pr123339.c 
b/gcc/testsuite/c-c++-common/cpp/pr123339.c
deleted file mode 100644
index 10312a8d6bac..000000000000
--- a/gcc/testsuite/c-c++-common/cpp/pr123339.c
+++ /dev/null
@@ -1,9 +0,0 @@
-/* PR preprocessor/123339 */
-/* { dg-do compile } */
-
-/* { dg-error "'__has_include' used outside of preprocessing directive" "" { 
target *-*-* } .+5 } */
-/* { dg-error "missing terminating '>' character" "" { target *-*-* } .+4 } */
-/* { dg-error "missing '\\\(' before '__has_include' operand" "" { target 
*-*-* } .+3 } */
-/* { dg-error "expected identifier or '\\\(' before numeric constant" "" { 
target c } .+2 } */
-/* { dg-error "expected unqualified-id before numeric constant" "" { target 
c++ } .+1 } */
-__has_include <"foo"
diff --git a/libcpp/directives.cc b/libcpp/directives.cc
index 9aced277b07f..479f8c716e8b 100644
--- a/libcpp/directives.cc
+++ b/libcpp/directives.cc
@@ -127,6 +127,7 @@ static void do_pragma_warning_or_error (cpp_reader *, bool 
error);
 static void do_pragma_warning (cpp_reader *);
 static void do_pragma_error (cpp_reader *);
 static void do_linemarker (cpp_reader *);
+static const cpp_token *get_token_no_padding (cpp_reader *);
 static const cpp_token *get__Pragma_string (cpp_reader *);
 static void destringize_and_run (cpp_reader *, const cpp_string *,
                                 location_t);
@@ -749,7 +750,7 @@ glue_header_name (cpp_reader *pfile)
   buffer = XNEWVEC (char, capacity);
   for (;;)
     {
-      token = _cpp_get_token_no_padding (pfile);
+      token = get_token_no_padding (pfile);
 
       if (token->type == CPP_GREATER)
        break;
@@ -791,7 +792,7 @@ parse_include (cpp_reader *pfile, int *pangle_brackets,
   const cpp_token *header;
 
   /* Allow macro expansion.  */
-  header = _cpp_get_token_no_padding (pfile);
+  header = get_token_no_padding (pfile);
   *location = header->src_loc;
   if ((header->type == CPP_STRING && header->val.str.text[0] != 'R')
       || header->type == CPP_HEADER_NAME)
@@ -1830,6 +1831,18 @@ do_pragma_error (cpp_reader *pfile)
   do_pragma_warning_or_error (pfile, true);
 }
 
+/* Get a token but skip padding.  */
+static const cpp_token *
+get_token_no_padding (cpp_reader *pfile)
+{
+  for (;;)
+    {
+      const cpp_token *result = cpp_get_token (pfile);
+      if (result->type != CPP_PADDING)
+       return result;
+    }
+}
+
 /* Check syntax is "(string-literal)".  Returns the string on success,
    or NULL on failure.  */
 static const cpp_token *
@@ -1838,17 +1851,23 @@ get__Pragma_string (cpp_reader *pfile)
   const cpp_token *string;
   const cpp_token *paren;
 
-  paren = _cpp_get_token_no_padding (pfile);
+  paren = get_token_no_padding (pfile);
+  if (paren->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
   if (paren->type != CPP_OPEN_PAREN)
     return NULL;
 
-  string = _cpp_get_token_no_padding (pfile);
+  string = get_token_no_padding (pfile);
+  if (string->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
   if (string->type != CPP_STRING && string->type != CPP_WSTRING
       && string->type != CPP_STRING32 && string->type != CPP_STRING16
       && string->type != CPP_UTF8STRING)
     return NULL;
 
-  paren = _cpp_get_token_no_padding (pfile);
+  paren = get_token_no_padding (pfile);
+  if (paren->type == CPP_EOF)
+    _cpp_backup_tokens (pfile, 1);
   if (paren->type != CPP_CLOSE_PAREN)
     return NULL;

Reply via email to