diff options
author | Kaveh R. Ghazi <ghazi@caip.rutgers.edu> | 2000-09-10 03:41:50 +0000 |
---|---|---|
committer | Kaveh Ghazi <ghazi@gcc.gnu.org> | 2000-09-10 03:41:50 +0000 |
commit | e1aa5140912178a5711762be987a0c10aad42e31 (patch) | |
tree | 7c23b23e1e31bfbc438ca968e64e66b8dfefe79b /gcc/cppmacro.c | |
parent | afa1738b588b778082a43c3c933f8a4b412a831d (diff) | |
download | gcc-e1aa5140912178a5711762be987a0c10aad42e31.zip gcc-e1aa5140912178a5711762be987a0c10aad42e31.tar.gz gcc-e1aa5140912178a5711762be987a0c10aad42e31.tar.bz2 |
cppmacro.c (check_trad_stringification): New function.
* cppmacro.c (check_trad_stringification): New function.
(save_expansion): If -Wtraditional, warn about stringification of
macro arguments.
testsuite:
* gcc.dg/cpp/tr-warn6.c: New test.
From-SVN: r36285
Diffstat (limited to 'gcc/cppmacro.c')
-rw-r--r-- | gcc/cppmacro.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c index 3c9ffb9..2b16fd47 100644 --- a/gcc/cppmacro.c +++ b/gcc/cppmacro.c @@ -52,6 +52,9 @@ static const cpp_toklist * save_expansion PARAMS((cpp_reader *, static unsigned int find_param PARAMS ((const cpp_token *, const cpp_token *)); static cpp_toklist * alloc_macro PARAMS ((cpp_reader *, struct macro_info *)); +static void check_trad_stringification PARAMS ((cpp_reader *, + const struct macro_info *, + const cpp_string *)); /* These are all the tokens that can have something pasted after them. Comma is included in the list only to support the GNU varargs extension @@ -502,6 +505,12 @@ save_expansion (pfile, info) continue; break; + case CPP_STRING: + case CPP_CHAR: + if (CPP_WTRADITIONAL (pfile) && list->paramc > 0) + check_trad_stringification (pfile, info, &token->val.str); + break; + default: break; } @@ -618,3 +627,46 @@ dump_macro_args (fp, list) } putc (')', fp); } + +/* Warn if a token in `string' matches one of the function macro + arguments in `info'. This function assumes that the macro is a + function macro and not an object macro. */ +static void +check_trad_stringification (pfile, info, string) + cpp_reader *pfile; + const struct macro_info *info; + const cpp_string *string; +{ + const U_CHAR *p, *q, *limit = string->text + string->len; + + /* Loop over the string. */ + for (p = string->text; p < limit; p = q) + { + const cpp_token *token; + + /* Find the start of an identifier. */ + while (!is_idstart (*p) && p < limit) p++; + + /* Find the end of the identifier. */ + q = p; + while (is_idchar (*q) && q < limit) q++; + + /* Loop over the function macro arguments to see if the + identifier inside the string matches one of them. */ + for (token = info->first_param; token < info->first; token++) + { + /* Skip the commas in between the arguments. */ + if (token->type != CPP_NAME) + continue; + + if (token->val.node->length == (q - p) + && !memcmp (p, token->val.node->name, (q - p))) + { + cpp_warning (pfile, + "macro arg \"%.*s\" would be stringified with -traditional.", + (int) (q - p), p); + break; + } + } + } +} |