[Bug preprocessor/65238] [5 Regression] __has_attribute is not handled properly with -traditional-cpp.

mpolacek at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 5 10:49:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65238

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This patch seems to make __has_attribute work even in traditional cpp:

--- a/libcpp/traditional.c
+++ b/libcpp/traditional.c
@@ -497,6 +497,18 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro
*macro)
                      fmacro.line = pfile->line_table->highest_line;
                      continue;
                    }
+                 else if ((node->flags & NODE_BUILTIN) != 0
+                          && node->value.builtin == BT_HAS_ATTRIBUTE)
+                   {
+                     pfile->out.cur = out_start;
+                     /* Skip "__has_attribute".  */
+                     _cpp_lex_token (pfile);
+                     push_replacement_text (pfile, node);
+                     /* Get rid of "(arg)" in the context.  */
+                     CUR (context) = pfile->buffer->cur;
+                     lex_state = ls_none;
+                     goto new_context;
+                   }
                  else if (!recursive_macro (pfile, node))
                    {
                      /* Remove the object-like macro's name from the


However there are other issues, so I'm afraid this will need more surgery than
that, so I'm dropping this for now :(.

1) We ICE with or without the patch on following valid code:

#define D unused
#if __has_attribute(D)
int i;
#endif

2) We ICE on the following invalid code with the patch:

#if __has_attribute(
int i;
#endif



More information about the Gcc-bugs mailing list