- implemented -Wcomment (currently non-working because cpp filters all
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 12 Sep 2008 04:35:50 +0000 (04:35 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Fri, 12 Sep 2008 04:35:50 +0000 (04:35 +0000)
  comments)

[r21877]

lexer.c
warning.c
warning.h

diff --git a/lexer.c b/lexer.c
index 10bca9d..5ca734a 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -1150,7 +1150,10 @@ static void skip_multiline_comment(void)
                case '/':
                        next_char();
                        if (c == '*') {
-                               /* TODO: nested comment, warn here */
+                               /* nested comment, warn here */
+                               if (warning.comment) {
+                                       warningf(&lexer_token.source_position, "'/*' within comment");
+                               }
                        }
                        break;
                case '*':
@@ -1192,6 +1195,15 @@ static void skip_line_comment(void)
                case '\r':
                        return;
 
+               case '\\':
+                       next_char();
+                       if (c == '\n' || c == '\r') {
+                               if (warning.comment)
+                                       warningf(&lexer_token.source_position, "multi-line comment");
+                               return;
+                       }
+                       break;
+
                default:
                        next_char();
                        break;
index f6a9fec..1347e90 100644 (file)
--- a/warning.c
+++ b/warning.c
@@ -26,6 +26,7 @@ warning_t warning = {
        .attribute                     = true,
        .char_subscripts               = true,
        .cast_qual                     = false,
+       .comment                       = false,
        .declaration_after_statement   = false,
        .deprecated_declarations       = true,
        .div_by_zero                   = true,
@@ -82,7 +83,7 @@ void set_warning_opt(const char *const opt)
                /* Note: this switched on a lot of more warnings than gcc's -Wall */
                SET(attribute);
                SET(char_subscripts);
-               // TODO SET(comment);
+               SET(comment);
                SET(empty_statement);
                SET(format);
                SET(implicit_function_declaration);
@@ -108,6 +109,7 @@ void set_warning_opt(const char *const opt)
        OPT("attribute",                     attribute);
        OPT("char-subscripts",               char_subscripts);
        OPT("cast-qual",                     cast_qual);
+       OPT("comment",                       comment);
        OPT("declaration-after-statement",   declaration_after_statement);
        OPT("deprecated-declarations",       deprecated_declarations);
        OPT("div_by_zero",                   div_by_zero);
index 8b885c8..12e4563 100644 (file)
--- a/warning.h
+++ b/warning.h
@@ -38,8 +38,8 @@ typedef struct warning_t {
 #if 0 // TODO
        bool cast_align:1;                    /**< Warn whenever a pointer is cast such that the required alignment of the target is increased */
        bool conversion:1;                    /**< Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype */
-       bool comment:1;                       /**< Warn whenever a comment-start sequence appears in a comment, or whenever a Backslash-Newline appears in a '//' comment. */
 #endif
+       bool comment:1;                       /**< Warn whenever a comment-start sequence appears in a comment, or whenever a Backslash-Newline appears in a '//' comment. */
        bool declaration_after_statement:1;   /**< Warn when a declaration is found after a statement in a block */
        bool deprecated_declarations:1;       /* TODO implement for types */ /**< Warn about uses of functions, variables and types marked as deprecated by using the 'deprecated' attribute */
        bool div_by_zero:1;                   /**< Warn about compile-time integer division by zero */