From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Brown Newsgroups: gmane.emacs.bugs Subject: bug#23771: Eliminating compiler warnings Date: Wed, 15 Jun 2016 21:38:19 -0400 Message-ID: <3f178870-9b99-8104-cb34-1967790436a5@cornell.edu> References: <08ec82d8-305e-5a95-7fbb-76162a49f5cc@cornell.edu> <83bn32eclh.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1466041166 8411 80.91.229.3 (16 Jun 2016 01:39:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jun 2016 01:39:26 +0000 (UTC) Cc: 23771@debbugs.gnu.org, Paul Eggert To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 16 03:39:15 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bDMH4-0006Iz-Ck for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Jun 2016 03:39:14 +0200 Original-Received: from localhost ([::1]:45937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDMH3-0000lQ-OP for geb-bug-gnu-emacs@m.gmane.org; Wed, 15 Jun 2016 21:39:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33603) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDMGw-0000kJ-Nu for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2016 21:39:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDMGs-00025g-Lo for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2016 21:39:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDMGs-00025c-Ix for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2016 21:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bDMGs-00088j-Bw for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2016 21:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ken Brown Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Jun 2016 01:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23771 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 23771-submit@debbugs.gnu.org id=B23771.146604111331251 (code B ref 23771); Thu, 16 Jun 2016 01:39:02 +0000 Original-Received: (at 23771) by debbugs.gnu.org; 16 Jun 2016 01:38:33 +0000 Original-Received: from localhost ([127.0.0.1]:42729 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDMGO-00087z-SI for submit@debbugs.gnu.org; Wed, 15 Jun 2016 21:38:33 -0400 Original-Received: from limerock04.mail.cornell.edu ([128.84.13.244]:38346) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDMGN-00087j-6c for 23771@debbugs.gnu.org; Wed, 15 Jun 2016 21:38:31 -0400 X-CornellRouted: This message has been Routed already. Original-Received: from authusersmtp.mail.cornell.edu (granite4.serverfarm.cornell.edu [10.16.197.9]) by limerock04.mail.cornell.edu (8.14.4/8.14.4_cu) with ESMTP id u5G1cJ5R030041; Wed, 15 Jun 2016 21:38:19 -0400 Original-Received: from [192.168.1.34] (c-50-138-241-230.hsd1.ct.comcast.net [50.138.241.230]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id u5G1cHBg001921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Wed, 15 Jun 2016 21:38:18 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 In-Reply-To: <83bn32eclh.fsf@gnu.org> X-PMX-Cornell-Gauge: Gauge=XXXXX X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:119610 Archived-At: On 6/15/2016 10:44 AM, Eli Zaretskii wrote: >> From: Ken Brown > Btw, it would have helped if you'd show examples of warnings that > eliminated by each patch in the set; for some of them, it's easy to > guess, others not so easy. I hope I did right. Thanks for the review. Sorry, I should have thought of giving examples of the warnings. >> Two comments: First, patch 0006-... is there because there might be a jump over an AUTO_STRING call. (This happens exactly once in the Cygwin-w32 build.) It seems stupid to have to worry about this. An alternative would be to just disable the -Wjump-misses-init warning. > > The warning is IMO important, it's just too bad GCC has false > positives with it. OK. >> Second, patch 0007-... is there because I couldn't think of a reasonable way to avoid -Waddress warnings when compiling w32fns.c, w32menu.c, and menu.c in the Cygwin-w32 build. Everything I thought of would have made the code very ugly. So I simply disabled that warning for the Cygwin-w32 build, and I took the liberty of doing the same thing for the MinGW build, which I think is also affected in some cases. If someone sees a better way of eliminating those warnings, that would be preferable. > > What warnings does that option produce? I'm not sure I've seen any > warnings about addresses, but maybe I misunderstand the nature of the > warning. Here's a typical example: ../../master/src/menu.c: In function ‘digest_single_submenu’: ../../master/src/menu.c:46:30: warning: the address of ‘AppendMenuW’ will always evaluate as ‘true’ [-Waddress] # define unicode_append_menu AppendMenuW ^ ../../master/src/menu.c:691:9: note: in expansion of macro ‘unicode_append_menu’ if (unicode_append_menu) ^ ../../master/src/menu.c:46:30: warning: the address of ‘AppendMenuW’ will always evaluate as ‘true’ [-Waddress] # define unicode_append_menu AppendMenuW ^ ../../master/src/menu.c:767:9: note: in expansion of macro ‘unicode_append_menu’ if (unicode_append_menu) ^ > What follows is specific comments to some hunks. > >> +#else /* not HAVE_WINDOW_SYSTEM */ >> + >> +_Noreturn void >> +decode_window_system_frame (Lisp_Object frame) >> +{ >> + error ("Window system is not in use"); >> +} >> + >> +_Noreturn void >> +check_window_system (struct frame *f) >> +{ >> + error ("Window system is not in use"); >> +} >> + >> +#endif /* not HAVE_WINDOW_SYSTEM */ > > What kind of warnings do you get without these changes? I don't > understand why this is needed. A build with no windows system yields these warnings: ../../warnings/src/frame.c: In function ‘decode_window_system_frame’: ../../warnings/src/frame.c:119:1: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] decode_window_system_frame (Lisp_Object frame) ^ ../../warnings/src/frame.c: In function ‘check_window_system’: ../../warnings/src/frame.c:129:1: warning: function might be candidate for attribute ‘noreturn’ [-Wsuggest-attribute=noreturn] check_window_system (struct frame *f) ^ >> --- a/src/font.c >> +++ b/src/font.c >> @@ -2863,7 +2863,10 @@ font_open_entity (struct frame *f, Lisp_Object entity, int pixel_size) >> struct font_driver_list *driver_list; >> Lisp_Object objlist, size, val, font_object; >> struct font *font; >> - int min_width, height, psize; >> + int height, psize; >> +#ifdef HAVE_WINDOW_SYSTEM >> + int min_width; >> +#endif >> >> eassert (FONT_ENTITY_P (entity)); >> size = AREF (entity, FONT_SIZE_INDEX); >> @@ -2907,10 +2910,12 @@ font_open_entity (struct frame *f, Lisp_Object entity, int pixel_size) >> Fcons (font_object, AREF (entity, FONT_OBJLIST_INDEX))); >> >> font = XFONT_OBJECT (font_object); >> +#ifdef HAVE_WINDOW_SYSTEM >> min_width = (font->min_width ? font->min_width >> : font->average_width ? font->average_width >> : font->space_width ? font->space_width >> : 1); >> +#endif > > Why not move the declaration of min_width and the calculation of its > value inside the #ifdef that uses it? Then you'd have eliminated 2 > #ifdef's. Good idea. I'll do that. >> --- a/src/frame.c >> +++ b/src/frame.c >> @@ -2143,13 +2143,12 @@ DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame, >> If omitted, FRAME defaults to the currently selected frame. */) >> (Lisp_Object frame) >> { >> - struct frame *f = decode_live_frame (frame); >> - >> /* Don't allow minibuf_window to remain on an iconified frame. */ >> check_minibuf_window (frame, EQ (minibuf_window, selected_window)); >> >> /* I think this should be done with a hook. */ >> #ifdef HAVE_WINDOW_SYSTEM >> + struct frame *f = decode_live_frame (frame); >> if (FRAME_WINDOW_P (f)) >> x_iconify_frame (f); >> #endif > > I understand the motivation, but this change has a downside: it > changes the order of validity check of the function arguments, and it > completely removes the check of the FRAME argument in the builds > without X. So I don't think we should make this change this way. Yes, I was very careless about that. I'm glad you caught it. > We could do something like this instead: > > #ifdef HAVE_WINDOW_SYSTEM > struct frame *f = decode_live_frame (frame); > #else > (void) decode_live_frame (frame); > #endif > > Or we could work around the warning in some other way, or even live > with it. I'm now thinking, especially in view of Richard's comments, that maybe we should just live with the "unused variable" warnings that can't be avoided without cluttering the code. >> @@ -3015,13 +3014,12 @@ or bottom edge of the outer frame of FRAME relative to the right or >> bottom edge of FRAME's display. */) >> (Lisp_Object frame, Lisp_Object x, Lisp_Object y) >> { >> - register struct frame *f = decode_live_frame (frame); >> - >> CHECK_TYPE_RANGED_INTEGER (int, x); >> CHECK_TYPE_RANGED_INTEGER (int, y); > >> /* I think this should be done with a hook. */ >> #ifdef HAVE_WINDOW_SYSTEM >> + register struct frame *f = decode_live_frame (frame); >> if (FRAME_WINDOW_P (f)) >> x_set_offset (f, XINT (x), XINT (y), 1); >> #endif > > Same comment here: the order of checking the arguments is important to > keep on all frames in all builds. Yes, more carelessness on my part. >> --- a/src/w32fns.c >> +++ b/src/w32fns.c >> @@ -6888,7 +6888,7 @@ A tooltip's maximum size is specified by `x-max-tooltip-size'. >> Text larger than the specified size is clipped. */) >> (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy) >> { >> - struct frame *tip_f; >> + struct frame *f, *tip_f; > > Please add comments explaining why 'f' is needed (here and > elsewhere). Someone who doesn't remember the w32 definition of > FRAME_DISPLAY_INFO will stumble on this one. OK >> +#ifdef HAVE_WINDOW_SYSTEM >> struct glyph *g; >> - >> +#endif > > Better moved inside the #ifdef where it's used, no? Yes. >> +#ifdef HAVE_WINDOW_SYSTEM >> if (clear_mouse_face (hlinfo)) >> cursor = No_Cursor; >> - >> +#endif > > This and other similar hunks that ifdef away clear_mouse_face are > incorrect: Emacs supports mouse highlight on TTY frames (if the mouse > is supported, e.g. via GPM or on MS-Windows/MS-DOS), so we must call > clear_mouse_face there as well. The same kind of carelessness yet again. (I was just trying to get rid of the warning that 'cursor' is unused, but I obviously threw away too much.) I'll fix all these and resend the patch. >> --- a/src/conf_post.h >> +++ b/src/conf_post.h >> @@ -211,7 +211,7 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */ >> extern void _DebPrint (const char *fmt, ...); >> # define DebPrint(stuff) _DebPrint stuff >> # else >> -# define DebPrint(stuff) >> +# define DebPrint(stuff) {} >> # endif >> #endif > > Yuck! Can we simply not use the "empty body" warning option? When is > it important to flag an empty body of a function? Here's a typical example: Code like this: if (!f->output_data.w32->asked_for_visible) DebPrint (("frame %p (%s) reexposed by WM_PAINT\n", f, SDATA (f->name))); leads to this warning (if EMACSDEBUG is not defined): ../../warnings/src/w32term.c: In function ‘w32_read_socket’: ../../warnings/src/w32term.c:4613:28: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] SDATA (f->name))); ^ But I'd be fine with just disabling this warning, at least for the w32 builds. Paul, do you think it's important to keep this warning? Thanks again for the review. Ken