From: Neil Booth Date: Mon, 26 Aug 2002 17:44:08 +0000 (+0000) Subject: c-opts.c (find_opt): Don't complain about wrong languages here. X-Git-Tag: releases/gcc-3.3.0~3161 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f66218653d7905c186e050208545d9f8d0b020f;p=thirdparty%2Fgcc.git c-opts.c (find_opt): Don't complain about wrong languages here. * c-opts.c (find_opt): Don't complain about wrong languages here. Return exact matches even for wrong language. (c_common_decode_option): Complain about wrong languages here. From-SVN: r56583 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 328a765893b9..552e434b0044 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2002-08-26 Neil Booth + + * c-opts.c (find_opt): Don't complain about wrong languages + here. Return exact matches even for wrong language. + (c_common_decode_option): Complain about wrong languages + here. + 2002-08-24 Stuart Hastings * function.h (struct function): Add flag diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 36f11f022882..1cc2048b633c 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -374,7 +374,10 @@ missing_arg (opt_index) Complications arise since some options can be suffixed with an argument, and multiple complete matches can occur, e.g. -pedantic and -pedantic-errors. Also, some options are only accepted by some - languages. */ + languages. If a switch matches for a different language and + doesn't match any alternatives for the true front end, the index of + the matched switch is returned anyway. The caller should check for + this case. */ static size_t find_opt (input, lang_flag) const char *input; @@ -382,7 +385,7 @@ find_opt (input, lang_flag) { size_t md, mn, mx; size_t opt_len; - size_t wrong_lang = N_OPTS; + size_t result = N_OPTS; int comp; mn = 0; @@ -403,13 +406,7 @@ find_opt (input, lang_flag) { /* The switch matches. It it an exact match? */ if (input[opt_len] == '\0') - { - exact_match: - if (cl_options[md].flags & lang_flag) - return md; - wrong_lang = md; - break; - } + return md; else { mn = md + 1; @@ -423,9 +420,10 @@ find_opt (input, lang_flag) /* Is this switch valid for this front end? */ if (!(cl_options[md].flags & lang_flag)) { - /* If subsequently we don't find a good match, - report this as a bad match. */ - wrong_lang = md; + /* If subsequently we don't find a better match, + return this and let the caller report it as a bad + match. */ + result = md; continue; } @@ -444,7 +442,7 @@ find_opt (input, lang_flag) if (memcmp (input, cl_options[md].opt_text, opt_len)) break; if (input[opt_len] == '\0') - goto exact_match; + return md; if (cl_options[md].flags & lang_flag && cl_options[md].flags & CL_JOINED) mx = md; @@ -455,10 +453,7 @@ find_opt (input, lang_flag) } } - if (wrong_lang != N_OPTS) - complain_wrong_lang (wrong_lang); - - return N_OPTS; + return result; } /* Defer option CODE with argument ARG. */ @@ -534,7 +529,7 @@ c_common_decode_option (argc, argv) const char *opt, *arg = 0; char *dup = 0; bool on = true; - int result; + int result, lang_flag; const struct cl_option *option; enum opt_code code; @@ -574,7 +569,8 @@ c_common_decode_option (argc, argv) result = cpp_handle_option (parse_in, argc, argv); /* Skip over '-'. */ - opt_index = find_opt (opt + 1, lang_flags[(c_language << 1) + flag_objc]); + lang_flag = lang_flags[(c_language << 1) + flag_objc]; + opt_index = find_opt (opt + 1, lang_flag); if (opt_index == N_OPTS) goto done; @@ -610,6 +606,15 @@ c_common_decode_option (argc, argv) } } + /* Complain about the wrong language after we've swallowed any + necessary extra argument. Eventually make this a hard error + after the call to find_opt, and return argc. */ + if (!(cl_options[opt_index].flags & lang_flag)) + { + complain_wrong_lang (opt_index); + goto done; + } + switch (code = option->opt_code) { case N_OPTS: /* Shut GCC up. */