[comp.windows.x] warning about gcc 1.36

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (01/08/90)

From a bug report:

    Versions 1.34 and 1.36 of GCC incorrectly compile the expression
    ``"..." == 0 ? exp1 : exp2'' into "exp1".

This expression is used by XtNewString (in lib/Xt/Intrinsic.h).

(As I stated before, we only tested R4 on gcc 1.35.)

casey@gauss.llnl.gov (Casey Leedom) (01/10/90)

| From: rws@EXPO.LCS.MIT.EDU (Bob Scheifler)
| From a bug report:
| 
|     Versions 1.34 and 1.36 of GCC incorrectly compile the expression
|     ``"..." == 0 ? exp1 : exp2'' into "exp1".
| 
| This expression is used by XtNewString (in lib/Xt/Intrinsic.h).

  It turns out there's a simple work around for this.  The problem only
appears to be with respect to equality comparisons between constant
strings and 0 in the ternary operator "?:".  Inequality comparisons seem
to work fine.  Thus, if you change the definition of the XtNewString
macro as follows:

*** mit/lib/Xt/Intrinsic.h-dist	Fri Dec 15 04:35:00 1989
--- mit/lib/Xt/Intrinsic.h	Sun Jan  7 20:43:15 1990
***************
*** 2144,2150 ****
  
  #define XtNew(type) ((type *) XtMalloc((unsigned) sizeof(type)))
  #define XtNewString(str) \
!     ((str) == NULL ? NULL : (strcpy(XtMalloc((unsigned)strlen(str) + 1), str)))
  
  extern char *XtMalloc(
  #if NeedFunctionPrototypes
--- 2144,2150 ----
  
  #define XtNew(type) ((type *) XtMalloc((unsigned) sizeof(type)))
  #define XtNewString(str) \
!     ((str) != NULL ? (strcpy(XtMalloc((unsigned)strlen(str) + 1), str)) : NULL)
  
  extern char *XtMalloc(
  #if NeedFunctionPrototypes

and then recompile the following files:

./lib/Xmu/CvtStdSel.c:105:	return XtNewString("SunOS");
./lib/Xmu/CvtStdSel.c:108:	return XtNewString("BSD");
./clients/xmh/toc.c:902:		    argv[0] = XtNewString("rmm");
./clients/xmh/toc.c:909:		    argv[0] = XtNewString("refile");
./clients/xmh/toc.c:942:		argv[cur++] = XtNewString("-src");
./clients/xmh/tocutil.c:270:    seq->name = XtNewString("all");

everything should work ...

  Note that Richard Stallman tells me that the current BETA version of
GCC 1.37 doesn't have this problem.  Richard mumbled something about
``soon'' with respect to a release date but didn't get any more specific.

Casey