diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 51920030ab883dbe9a0a41f3398c0d3acb7b9b70..0b859c56d6a28b9fc9972e484ea34249748f8f03 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2011-02-11  Joseph Myers  <joseph@codesourcery.com>
+
+	PR driver/47678
+	* gcc.c (main): Do not compile inputs if there were errors in
+	option handling.
+	* opts-common.c (read_cmdline_option): Check for wrong language
+	after other error checks.
+
 2011-02-11  Nathan Froyd  <froydnj@codesourcery.com>
 
 	* cgraph.c: Fix comment typos.
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 1736b091fb1143425a304622f2e1784100f19989..ec35ed01f6dcffb3115256a469827a8ae7844eab 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -6597,6 +6597,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
   if (n_infiles == added_libraries)
     fatal_error ("no input files");
 
+  if (seen_error ())
+    goto out;
+
   /* Make a place to record the compiler output file names
      that correspond to the input files.  */
 
@@ -6864,6 +6867,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
       printf ("%s\n", bug_report_url);
     }
 
+ out:
   return (signal_count != 0 ? 2
 	  : seen_error () ? (pass_exit_codes ? greatest_status : 1)
 	  : 0);
diff --git a/gcc/opts-common.c b/gcc/opts-common.c
index e6cb552df131a9b57bba4e30368d65f254f15cfa..3c4044a206377a26c75d58d963e7bcaa2a3136e9 100644
--- a/gcc/opts-common.c
+++ b/gcc/opts-common.c
@@ -960,12 +960,6 @@ read_cmdline_option (struct gcc_options *opts,
       return;
     }
 
-  if (decoded->errors & CL_ERR_WRONG_LANG)
-    {
-      handlers->wrong_lang_callback (decoded, lang_mask);
-      return;
-    }
-
   if (decoded->errors & CL_ERR_MISSING_ARG)
     {
       if (option->missing_argument_error)
@@ -1012,6 +1006,12 @@ read_cmdline_option (struct gcc_options *opts,
       return;
     }
 
+  if (decoded->errors & CL_ERR_WRONG_LANG)
+    {
+      handlers->wrong_lang_callback (decoded, lang_mask);
+      return;
+    }
+
   gcc_assert (!decoded->errors);
 
   if (!handle_option (opts, opts_set, decoded, lang_mask, DK_UNSPECIFIED,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fac52940dde8fb019a3a413d2ad453ab76a13ff2..b9406bab86db2de0ad909dc447a722e21394e81b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2011-02-11  Joseph Myers  <joseph@codesourcery.com>
+
+	PR driver/47678
+	* gcc.dg/opts-6.c: New test.
+
 2011-02-11  Jakub Jelinek  <jakub@redhat.com>
 
 	PR debug/47684
diff --git a/gcc/testsuite/gcc.dg/opts-6.c b/gcc/testsuite/gcc.dg/opts-6.c
new file mode 100644
index 0000000000000000000000000000000000000000..b0441dc39391c69166dcb9cb1f2f662f67a2d7d8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/opts-6.c
@@ -0,0 +1,6 @@
+/* Missing option arguments take precedence over wrong-language
+   warnings.  */
+/* { dg-do compile } */
+/* { dg-options "-ftemplate-depth=" } */
+
+/* { dg-error "missing argument" "" { target *-*-* } 0 } */