[gnu.gcc] Wanted: better way to catch '#define q

ado@elsie.UUCP (Arthur David Olson) (10/09/88)

I've attached a change I made to "cccp.c" to issue warnings about unused
macro parameters.  I did this so that gcc could catch things such as
	#define quote(s)	"s"
that (non-portably) used features of old cpp to generate quoted strings.
Why?  Well, given the above definition, the invocation
	quote(unquote)
would produce
	"unquote"
under old cpp while producing
	"s"
under gcc in its ANSI-conformant incarnation.  I wanted to ensure that if such
a "quiet change" took place, I'd be warned about it.

If you know of a better way of catching such quiet changes, I'd appreciate
hearing from you.
-- 
	ado@ncifcrf.gov			ADO is a trademark of Ampex.

*** 1.1/cccp.c	Sat Oct  8 15:54:52 1988
--- 1.3/cccp.c	Sat Oct  8 15:55:03 1988
***************
*** 249,254 ****
--- 249,258 ----
  
  int warn_trigraphs;
  
+ /* Nonzero means warn about unused macro parameters.  */
+ 
+ int warn_unused;
+ 
  /* Nonzero means try to imitate old fashioned non-ANSI preprocessor.  */
  
  int traditional;
***************
*** 666,671 ****
--- 670,677 ----
  	break;
  
        case 'W':
+ 	if (!strcmp (argv[i], "-Wunused"))
+ 	  warn_unused = 1;
  	if (!strcmp (argv[i], "-Wtrigraphs")) {
  	  warn_trigraphs = 1;
  	  no_trigraphs = 0;
***************
*** 673,678 ****
--- 679,685 ----
  	if (!strcmp (argv[i], "-Wcomments"))
  	  warn_comments = 1;
  	if (!strcmp (argv[i], "-Wall")) {
+ 	  warn_unused = 1;
  	  warn_trigraphs = 1;
  	  no_trigraphs = 0;
  	  warn_comments = 1;
***************
*** 2521,2526 ****
--- 2528,2534 ----
    U_CHAR *name;
    int length;
    int argno;
+   int used;
  };
  
  /* Process a #define command.
***************
*** 2574,2579 ****
--- 2582,2588 ----
        temp->name = bp;
        temp->next = arg_ptrs;
        temp->argno = argno++;
+       temp->used = 0;
        arg_ptrs = temp;
  
        if (!is_idstart[*bp])
***************
*** 2614,2619 ****
--- 2623,2636 ----
        struct arglist *temp;
        int i = 0;
        for (temp = arg_ptrs; temp; temp = temp->next) {
+ 	if (!temp->used && warn_unused && defn->length > 2) {
+ 	  char buf[132];
+ 
+ 	  (void) sprintf(buf, "argument %*.*s unused in macro %*.*s",
+ 	    temp->length, temp->length, temp->name,
+ 	    sym_length, sym_length, symname);
+ 	  warning(buf);
+ 	}
  	bcopy (temp->name, &defn->argnames[i], temp->length);
  	i += temp->length;
  	if (temp->next != 0) {
***************
*** 2922,2927 ****
--- 2939,2945 ----
  	  if (arg->name[0] == c
  	      && arg->length == id_len
  	      && strncmp (arg->name, id_beg, id_len) == 0) {
+ 	    arg->used = 1;
  	    /* make a pat node for this arg and append it to the end of
  	       the pat list */
  	    tpat = (struct reflist *) xmalloc (sizeof (struct reflist));