diff --git a/src/main.c b/src/main.c
index 4e01a17..ffe973b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1267,7 +1267,7 @@ grepfile (char const *file, struct stats *stats)
     status = count + 2;
   else
     {
-      if (count_matches)
+      if (count_matches && (count || (count_matches == 1)))
         {
           if (out_file)
             {
@@ -2085,14 +2085,23 @@ main (int argc, char **argv)
       }
 
   /* POSIX.2 says that -q overrides -l, which in turn overrides the
-     other output options.  */
+     other output options.  We violate this slightly by allowing -c
+     and -l to coexist (print 'file:count' but skip if count==0).  */
   if (exit_on_match)
-    list_files = 0;
-  if (exit_on_match | list_files)
     {
+      list_files = 0;
       count_matches = 0;
       done_on_match = 1;
     }
+  else if (list_files && count_matches)
+    {
+      list_files = 0;
+      count_matches = 2;
+      done_on_match = 0;
+    }
+  else if (list_files)
+    done_on_match = 1;
+
   out_quiet = count_matches | done_on_match;
 
   if (out_after < 0)
