diff options
-rw-r--r-- | clang/include/clang/Basic/DiagnosticLexKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 5 | ||||
-rw-r--r-- | clang/test/Preprocessor/line-directive.c | 2 |
3 files changed, 9 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 77406f5652d..92e134963d0 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -223,6 +223,8 @@ def err_pp_line_requires_integer : Error< "#line directive requires a positive integer argument">; def err_pp_line_invalid_filename : Error< "invalid filename for #line directive">; +def warn_pp_line_decimal : Warning< + "#line directive requires decimal line number">; def err_pp_linemarker_requires_integer : Error< "line marker directive requires a positive integer argument">; def err_pp_linemarker_invalid_filename : Error< diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index ce86d0edca0..2dfb6233bdf 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -650,6 +650,11 @@ static bool GetLineValue(Token &DigitTok, unsigned &Val, return true; } + // Warn about hex and octal line numbers. Do this after the check for 0, + // because it is octal. + if (Literal.getRadix() != 10) + PP.Diag(DigitTok, diag::warn_pp_line_decimal); + return false; } diff --git a/clang/test/Preprocessor/line-directive.c b/clang/test/Preprocessor/line-directive.c index 1dd8b292d2e..8877406adc2 100644 --- a/clang/test/Preprocessor/line-directive.c +++ b/clang/test/Preprocessor/line-directive.c @@ -68,3 +68,5 @@ typedef int w; // expected-error {{redefinition of typedef 'w' is invalid in C} #line 2 "foo.c" EMPTY( ) #line 2 "foo.c" NONEMPTY( ) // expected-warning{{extra tokens at end of #line directive}} +// PR3940 +#line 0xf // expected-warning {{#line directive requires decimal line number}} |