https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61854

            Bug ID: 61854
           Summary: Warning single-line comment for -std=c89?
           Product: gcc
           Version: 4.10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

Currently there is no warning on single-line comments for -std=c89. For
example, when I am compiling the following code extracted from SPEC, GCC emits
several errors and Clang emits a warning saying that the single-line comment is
not supported in the c89 language. IMHO, it is worth considering to emit such a
warning, as it is the root cause of the errors, making it easier to understand
the errors. 

$: cat t.c
#include <stdio.h>

void
_E_pr_info_header(char const *f, long ln, char const *msg)                      
{                                                                               
  //SPEC lots of informationals are printed for validation; use stdout          
  //     intead of stderr so as to prefer buffered io                           

      /* make different format so as not to be parsed by emacs compile */       
      (void) fprintf(stdout, "%s: %s(%ld): ", msg, f, ln);                      
}                                                                               

$: gcc-trunk -c -pedantic -Wall -Wextra -std=c89 t.c
t.c: In function ‘_E_pr_info_header’:
t.c:6:3: error: expected expression before ‘/’ token
   //SPEC lots of informationals are printed for validation; use stdout         
   ^
t.c:6:61: error: unknown type name ‘use’
   //SPEC lots of informationals are printed for validation; use stdout         
                                                             ^
t.c:7:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘/’
token
   //     intead of stderr so as to prefer buffered io                          
   ^
t.c:6:61: warning: ISO C90 forbids mixed declarations and code [-Wpedantic]
   //SPEC lots of informationals are printed for validation; use stdout         
                                                             ^
t.c:4:31: warning: unused parameter ‘f’ [-Wunused-parameter]
 _E_pr_info_header(char const *f, long ln, char const *msg)                     
                               ^
t.c:4:39: warning: unused parameter ‘ln’ [-Wunused-parameter]
 _E_pr_info_header(char const *f, long ln, char const *msg)                     
                                       ^
t.c:4:55: warning: unused parameter ‘msg’ [-Wunused-parameter]
 _E_pr_info_header(char const *f, long ln, char const *msg)                     
                                                       ^


$: clang-trunk -c -pedantic -Wcomment -std=c89 t.c
t.c:6:3: warning: // comments are not allowed in this language [-Wcomment]
  //SPEC lots of informationals are printed for validation; use stdout          
  ^
1 warning generated.

Reply via email to