ref: 79653a933b3cfb9dafed904d6c4831d3c77c3e9c
parent: 73484d036e8ddffd310884ab93be6ce4ae04a53c
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jun 14 08:58:39 EDT 2016
[cc1] Deal with redefinitions in the command line The POSIX standard commands that -D definitions without replacement parts must be defined with a replacement string "1". We also warn in the case of redefining any macro, even when they have the same replacement string. It is easier and it is a good practice to define them only once.
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -26,15 +26,24 @@
{
char *p, *q;
Symbol *sym;
+ char def[] = "=1";
- if ((p = strchr(s, '=')) != NULL) {
- *p++='\0';
- q = xmalloc(strlen(p) + 4);
- sprintf(q, "-1#%s", p);
- p = q;
+ if ((p = strchr(s, '=')) == NULL)
+ p = def;
+ *p++='\0';
+ q = xmalloc(strlen(p) + 4);
+ sprintf(q, "-1#%s", p);
+
+ sym = lookup(NS_CPP, s);
+ if (sym->flags & SDECLARED) {
+ warn("'%s' redefined");
+ free(sym->u.s);
+ } else {
+ install(NS_CPP, sym);
+ sym->flags |= SDECLARED|SSTRING;
}
- sym = install(NS_CPP, lookup(NS_CPP, s));
- sym->u.s = p;
+
+ sym->u.s = q;
return sym;
}
--
⑨