From: Ted Kremenek Date: Thu, 2 Feb 2012 00:16:13 +0000 (+0000) Subject: Per discussion on cfe-dev, remove '#error' and '#warning' from diagnostic text. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34a2c42ba8cc58a404238a3c1cbc4a7442e57832;p=clang Per discussion on cfe-dev, remove '#error' and '#warning' from diagnostic text. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149566 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 3a564c4aa8..fde522c573 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -148,8 +148,13 @@ def err_invalid_pth_file : Error< //===----------------------------------------------------------------------===// // Preprocessor Diagnostics //===----------------------------------------------------------------------===// -def pp_hash_warning : Warning<"#warning%0">, + +let CategoryName = "User Defined Issues" in { +def pp_hash_warning : Warning<"%0">, InGroup, DefaultWarnShowInSystemHeader; +def err_pp_hash_error : Error<"%0">; +} + def pp_include_next_in_primary : Warning< "#include_next in primary source file">; def pp_include_macros_out_of_predefines : Error< @@ -223,7 +228,6 @@ def warn_cxx98_compat_empty_fnmacro_arg : Warning< InGroup, DefaultIgnore; def err_pp_invalid_directive : Error<"invalid preprocessing directive">; -def err_pp_hash_error : Error<"#error%0">; def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal; def err_pp_error_opening_file : Error< "error opening file '%0': %1">, DefaultFatal; diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 76955604b0..9f2309e801 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1007,10 +1007,18 @@ void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, // collapse multiple consequtive white space between tokens, but this isn't // specified by the standard. std::string Message = CurLexer->ReadToEndOfLine(); + + // Find the first non-whitespace character, so that we can make the + // diagnostic more succinct. + StringRef Msg(Message); + size_t i = Msg.find_first_not_of(' '); + if (i < Msg.size()) + Msg = Msg.substr(i); + if (isWarning) - Diag(Tok, diag::pp_hash_warning) << Message; + Diag(Tok, diag::pp_hash_warning) << Msg; else - Diag(Tok, diag::err_pp_hash_error) << Message; + Diag(Tok, diag::err_pp_hash_error) << Msg; } /// HandleIdentSCCSDirective - Handle a #ident/#sccs directive. diff --git a/test/Frontend/rewrite-macros.c b/test/Frontend/rewrite-macros.c index f44e545728..bc7479693b 100644 --- a/test/Frontend/rewrite-macros.c +++ b/test/Frontend/rewrite-macros.c @@ -9,7 +9,7 @@ A(1,2) _Pragma("mark") // RUN: grep "//#warning eek" %t -/* expected-warning {{#warning eek}} */ #warning eek +/* expected-warning {{eek}} */ #warning eek // RUN: grep "//#pragma mark mark" %t #pragma mark mark diff --git a/test/Index/retain-target-options.c b/test/Index/retain-target-options.c index 797971d12c..2fba476fb1 100644 --- a/test/Index/retain-target-options.c +++ b/test/Index/retain-target-options.c @@ -2,7 +2,7 @@ // RUN: c-index-test -test-load-source-reparse 1 all -target x86_64-apple-darwin10.0.0 -msse4.1 %s 2>&1 | FileCheck %s // RUN: c-index-test -test-load-source-reparse 5 all -target x86_64-apple-darwin10.0.0 -msse4.1 %s 2>&1 | FileCheck %s -// CHECK: error: #error SSE4_1 used +// CHECK: error: SSE4_1 used #if defined(__SSE4_1__) #error SSE4_1 used #endif diff --git a/test/Misc/serialized-diags-no-category.c b/test/Misc/serialized-diags-no-category.c index 9c92ac3330..3074892e0e 100644 --- a/test/Misc/serialized-diags-no-category.c +++ b/test/Misc/serialized-diags-no-category.c @@ -7,6 +7,6 @@ // This test case tests that we can handle both fatal errors and errors without categories. -// CHECK: {{.*[/\\]}}serialized-diags-no-category.c:1:2: error: #error foo [] +// CHECK: {{.*[/\\]}}serialized-diags-no-category.c:1:2: error: foo [] // CHECK: Number of diagnostics: 2 diff --git a/test/Misc/warn-in-system-header.c b/test/Misc/warn-in-system-header.c index 7e4615e65e..6e0237d0dc 100644 --- a/test/Misc/warn-in-system-header.c +++ b/test/Misc/warn-in-system-header.c @@ -1,4 +1,4 @@ // RUN: %clang_cc1 -isystem %S %s -fsyntax-only -verify #include -// expected-warning {{#warning}} +// expected-warning {{the cake is a lie}} diff --git a/test/Preprocessor/line-directive.c b/test/Preprocessor/line-directive.c index 102469449e..28e93029a5 100644 --- a/test/Preprocessor/line-directive.c +++ b/test/Preprocessor/line-directive.c @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s -// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: #error ABC' -// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: #error DEF' +// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:92:2: error: ABC' +// RUN: %clang_cc1 -E %s 2>&1 | grep 'blonk.c:93:2: error: DEF' #line 'a' // expected-error {{#line directive requires a positive integer argument}} #line 0 // expected-error {{#line directive requires a positive integer argument}}