This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/16119] New: In C language diagnostic messages, %E should but cannot display general expressions


I want to add (or enhance) warnings to gcc, such as:
        warning ("operation on %qE may be undefined", written);
but the pretty-printer %E aborts on anything more complicated
than an identifier node.

I would like %E to handle general expressions.
Here is how I fixed it in gcc-3.5-20040620:

chaos$ diff -c1 c-objc-common.c.orig c-objc-common.c
*** c-objc-common.c.orig        Sun Jun 20 04:34:43 2004
--- c-objc-common.c     Mon Jun 21 13:05:45 2004
***************
*** 274,280 ****
      case 'E':
!       if (TREE_CODE (t) == IDENTIFIER_NODE)
!       n = IDENTIFIER_POINTER (t);
!       else
!         return false;
!       break;
   
--- 274,278 ----
      case 'E':
!       dump_generic_node (pp, t, 0, 0, false);
!       return true;
!

   ==================

Unfortunately that exposed glitches in the handling of `line_length'
in pretty-print.c  line_length is zero initially, incremented as characters
are accumulated, and reset to zero by pp_newline.
But pp_write_text_to_stream/pp_base_clear_output_area also resets it to zero,
which I think is a bug.  So I removed the reset in pp_base_clear_output_area,
and changed pp_base_flush to call pp_newline rather than fputc.
Here is the diff for that:

chaos$ diff -c1 pretty*.orig pretty*.c
*** pretty-print.c.orig Sat May 29 16:10:10 2004
--- pretty-print.c      Mon Jun 21 13:06:14 2004
***************
*** 367,371 ****
  {
    pp_write_text_to_stream (pp);
    pp_clear_state (pp);
-   fputc ('\n', pp->buffer->stream);
    fflush (pp->buffer->stream);
--- 367,371 ----
  {
+   pp_newline (pp);
    pp_write_text_to_stream (pp);
    pp_clear_state (pp);
    fflush (pp->buffer->stream);
***************
*** 389,391 ****
    obstack_free (&pp->buffer->obstack, obstack_base (&pp->buffer->obstack));
-   pp->buffer->line_length = 0;
  }
--- 389,390 ----

   ==================

Regardless of how this is fixed, I think it should be.
Thanks much for considering this,

Tom Truscott
trt@sas.com

-- 
           Summary: In C language diagnostic messages, %E should but cannot
                    display general expressions
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: trt at acm dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16119


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]