From tms@mail.ptd.net  Thu May 25 20:08:23 2000
Return-Path: <tms@mail.ptd.net>
Received: from mail.ptd.net (mail1.ha-net.ptd.net [207.44.96.65])
	by hub.freebsd.org (Postfix) with SMTP id C6A8F37B820
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 25 May 2000 20:08:02 -0700 (PDT)
	(envelope-from tms@mail.ptd.net)
Received: (qmail 25787 invoked from network); 26 May 2000 03:07:58 -0000
Received: from du146.cli.ptd.net (HELO beowulf.bsd.home) (204.186.33.146)
  by mail.ptd.net with SMTP; 26 May 2000 03:07:58 -0000
Received: (from tms@localhost)
	by beowulf.bsd.home (8.9.3/8.9.3) id WAA01736;
	Thu, 25 May 2000 22:52:41 -0400 (EDT)
	(envelope-from tms)
Message-Id: <200005260252.WAA01736@beowulf.bsd.home>
Date: Thu, 25 May 2000 22:52:41 -0400 (EDT)
From: tms2@mail.ptd.net
Sender: tms@mail.ptd.net
Reply-To: tms2@mail.ptd.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: lint does not understand C++-style comments
X-Send-Pr-Version: 3.2

>Number:         18821
>Category:       misc
>Synopsis:       lint does not understand C++-style comments
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 25 20:10:01 PDT 2000
>Closed-Date:    Sun Jul 8 03:39:06 PDT 2001
>Last-Modified:  Sun Jul 08 03:39:56 PDT 2001
>Originator:     Thomas M. Sommers
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
>Environment:
>Description:
lint does not understand C++-style comments.  gcc does understand them,
and they are part of the new C99 standard.
>How-To-Repeat:
>Fix:
*** scan.l.orig	Thu May 25 21:00:46 2000
--- scan.l	Thu May 25 21:49:15 2000
***************
*** 50,55 ****
--- 50,58 ----
  
  #define CHAR_MASK	(~(~0 << CHAR_BIT))
  
+ #define C_STYLE 1
+ #define CPP_STYLE 2
+ 
  /* XXX declaration of strtouq() is missing in stdlib.h ? */
  extern	u_quad_t strtouq __P((const char *, char **, int));
  
***************
*** 78,84 ****
  static	int	wccon __P((void));
  static	int	getescc __P((int));
  static	void	directive __P((void));
! static	void	comment __P((void));
  static	int	string __P((void));
  static	int	wcstrg __P((void));
  
--- 81,87 ----
  static	int	wccon __P((void));
  static	int	getescc __P((int));
  static	void	directive __P((void));
! static	void	comment __P((int));
  static	int	string __P((void));
  static	int	wcstrg __P((void));
  
***************
*** 153,159 ****
  ^#.*$				directive();
  \n				incline();
  \t|" "|\f|\v			;
! "/*"				comment();
  .				badchar(yytext[0]);
  
  %%
--- 156,163 ----
  ^#.*$				directive();
  \n				incline();
  \t|" "|\f|\v			;
! "/*"				comment(C_STYLE);
! "//"				comment(CPP_STYLE);
  .				badchar(yytext[0]);
  
  %%
***************
*** 1003,1009 ****
   * parsed and a function which handles this comment is called.
   */
  static void
! comment()
  {
  	int	c, lc;
  	static struct {
--- 1007,1013 ----
   * parsed and a function which handles this comment is called.
   */
  static void
! comment(int style)
  {
  	int	c, lc;
  	static struct {
***************
*** 1035,1041 ****
  	eoc = 0;
  
  	/* Skip white spaces after the start of the comment */
! 	while ((c = inpc()) != EOF && isspace(c)) ;
  
  	/* Read the potential keyword to keywd */
  	l = 0;
--- 1039,1054 ----
  	eoc = 0;
  
  	/* Skip white spaces after the start of the comment */
! 	if ( style == C_STYLE ) {
! 		while ((c = inpc()) != EOF && isspace(c)) ;
! 	}
! 	else {
! 		while ((c = inpc()) != EOF && c != '\n' && isspace(c)) ;
! 		if  ( c == '\n' ) {
! 			eoc = 1;
! 			goto skip_rest;
! 		}
! 	}
  
  	/* Read the potential keyword to keywd */
  	l = 0;
***************
*** 1054,1062 ****
  		goto skip_rest;
  
  	/* skip white spaces after the keyword */
! 	while (c != EOF && isspace(c))
! 		c = inpc();
! 
  	/* read the argument, if the keyword accepts one and there is one */
  	l = 0;
  	if (keywtab[i].arg) {
--- 1067,1081 ----
  		goto skip_rest;
  
  	/* skip white spaces after the keyword */
! 	if ( style == C_STYLE ) {
! 		while (c != EOF && isspace(c))
! 			c = inpc();
! 	}
! 	else {
! 		while (c != EOF && c != '\n' && isspace(c))
! 			c = inpc();
! 	}
! 		
  	/* read the argument, if the keyword accepts one and there is one */
  	l = 0;
  	if (keywtab[i].arg) {
***************
*** 1069,1078 ****
  	a = l != 0 ? atoi(arg) : -1;
  
  	/* skip white spaces after the argument */
! 	while (c != EOF && isspace(c))
! 		c = inpc();
  
! 	if (c != '*' || (c = inpc()) != '/') {
  		if (keywtab[i].func != linted)
  			/* extra characters in lint comment */
  			warning(257);
--- 1088,1104 ----
  	a = l != 0 ? atoi(arg) : -1;
  
  	/* skip white spaces after the argument */
! 	if ( style == C_STYLE ) {
! 		while (c != EOF && isspace(c))
! 			c = inpc();
! 	}
! 	else {
! 		while (c != EOF && c != '\n' && isspace(c))
! 			c = inpc();
! 	}
  
! 	if ( (style == C_STYLE && (c != '*' || (c = inpc()) != '/'))
! 			|| (style == CPP_STYLE && c != '\n') ) {
  		if (keywtab[i].func != linted)
  			/* extra characters in lint comment */
  			warning(257);
***************
*** 1088,1102 ****
  		(*keywtab[i].func)(a);
  
   skip_rest:
! 	while (!eoc) {
! 		lc = c;
! 		if ((c = inpc()) == EOF) {
! 			/* unterminated comment */
! 			error(256);
! 			break;
  		}
! 		if (lc == '*' && c == '/')
! 			eoc = 1;
  	}
  }
  
--- 1114,1133 ----
  		(*keywtab[i].func)(a);
  
   skip_rest:
! 	if ( style == C_STYLE ) {
! 		while (!eoc) {
! 			lc = c;
! 			if ((c = inpc()) == EOF) {
! 				/* unterminated comment */
! 				error(256);
! 				break;
! 			}
! 			if (lc == '*' && c == '/')
! 				eoc = 1;
  		}
! 	}
! 	else {
! 		while ( (c = inpc()) != '\n' ) ;
  	}
  }
  



>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: schweikh 
State-Changed-When: Sun Jul 8 03:39:06 PDT 2001 
State-Changed-Why:  
Lint(1) says "lint - a C program verifier", so it is not clear it should 
unterstand C++ syntax. While // is part of ISO 9899:1999 (C99) our lint  
does not support any new syntax introduced by C99, like struct literals, 
flexible arrays and others. So instead of supporting just one feature of 
C99, the // comments, I think it is better to have lint actually reject 
// as it is clearly a syntax error for C89 and many compilers do not            understand it. Lint is also a portability checker, intended to pick             fluff off of C code and // is non-portable fluff. BTW, gcc does NOT 
understand // in -ansi -pedantic mode. 

Of course we would be pleased if you provided a patch to make lint 
(optionally) fully C99 aware and this would have a near 100% chance of 
making it into the tree. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18821 
>Unformatted:
