From ff1ed985ede24b9a45e52d726db95767e35fe21e Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 15 Feb 2011 23:45:31 +0000 Subject: [PATCH] Warn for missing terminating " or ' instead of error for gcc compatibility. Fixed rdar://8914293. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125616 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticLexKinds.td | 4 ++-- lib/Lex/Lexer.cpp | 4 ++-- test/Lexer/rdar-8914293.c | 7 +++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test/Lexer/rdar-8914293.c diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 85573de02c..813e2983ef 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -45,8 +45,8 @@ def charize_microsoft_ext : Extension<"@# is a microsoft extension">; def ext_token_used : Extension<"extension used">; -def err_unterminated_string : Error<"missing terminating '\"' character">; -def err_unterminated_char : Error<"missing terminating ' character">; +def warn_unterminated_string : Warning<"missing terminating '\"' character">; +def warn_unterminated_char : Warning<"missing terminating ' character">; def err_empty_character : Error<"empty character constant">; def err_unterminated_block_comment : Error<"unterminated /* comment">; def err_invalid_character_to_charify : Error< diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index fd5bb617a0..b17198b219 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1162,7 +1162,7 @@ void Lexer::LexStringLiteral(Token &Result, const char *CurPtr, bool Wide) { if (C == 0 && PP && PP->isCodeCompletionFile(FileLoc)) PP->CodeCompleteNaturalLanguage(); else if (!isLexingRawMode() && !Features.AsmPreprocessor) - Diag(BufferPtr, diag::err_unterminated_string); + Diag(BufferPtr, diag::warn_unterminated_string); FormTokenWithChars(Result, CurPtr-1, tok::unknown); return; } @@ -1241,7 +1241,7 @@ void Lexer::LexCharConstant(Token &Result, const char *CurPtr) { if (C == 0 && PP && PP->isCodeCompletionFile(FileLoc)) PP->CodeCompleteNaturalLanguage(); else if (!isLexingRawMode() && !Features.AsmPreprocessor) - Diag(BufferPtr, diag::err_unterminated_char); + Diag(BufferPtr, diag::warn_unterminated_char); FormTokenWithChars(Result, CurPtr-1, tok::unknown); return; } else if (C == 0) { diff --git a/test/Lexer/rdar-8914293.c b/test/Lexer/rdar-8914293.c new file mode 100644 index 0000000000..e39e4f1904 --- /dev/null +++ b/test/Lexer/rdar-8914293.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// rdar://8914293 +// We want be compatible with gcc and warn, not error. + +/* expected-warning {{missing terminating}} */ #define FOO "foo +/* expected-warning {{missing terminating}} */ #define KOO 'k -- 2.40.0