This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Wrong frontend options are a warning, not error
- From: Neil Booth <neil at daikokuya dot co dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 26 Aug 2002 05:18:47 +0100
- Subject: RFA: Wrong frontend options are a warning, not error
When I created c-opts.c, I originally made it an error to specify
a switch to e.g. C++ that was C-only. Someone (Fergus?) requested
it be made a warning to be better backwards compatible.
I did that, but toplev.c was still raising an "unrecognised option"
error as c-opts.c was claiming zero switches were being processed.
This fixes that. OK to commit (being a bug fix)?
Neil.
* 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.
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.14
diff -u -p -r1.14 c-opts.c
--- c-opts.c 14 Aug 2002 22:34:47 -0000 1.14
+++ c-opts.c 26 Aug 2002 04:04:28 -0000
@@ -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;
@@ -608,6 +604,15 @@ c_common_decode_option (argc, argv)
result = argc;
goto done;
}
+ }
+
+ /* 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)