From e6d1289f4ac88a3ac488654544b1c2e3bc567a01 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 22 Jan 2020 08:49:12 +0100 Subject: [PATCH] diagnostics: handle -fno-caret in the called functions Don't force callers of location_caret to have to deal with flags that disable it. * src/location.h, src/location.c (location_caret) (location_caret_suggestion): Early return if disabled. * src/complain.c: Simplify. --- src/complain.c | 5 ++--- src/location.c | 4 ++++ src/location.h | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/complain.c b/src/complain.c index 04e22708..b98fea05 100644 --- a/src/complain.c +++ b/src/complain.c @@ -464,7 +464,7 @@ error_message (const location *loc, int *indent, warnings flags, { putc ('\n', stderr); flush (stderr); - if (loc && feature_flag & feature_caret && !(flags & no_caret)) + if (loc && !(flags & no_caret)) location_caret (*loc, style, stderr); } } @@ -555,8 +555,7 @@ deprecated_directive (location const *loc, char const *old, char const *upd) complain (loc, Wdeprecated, _("deprecated directive: %s, use %s"), quote (old), quote_n (1, upd)); - if (feature_flag & feature_caret) - location_caret_suggestion (*loc, upd, stderr); + location_caret_suggestion (*loc, upd, stderr); /* Register updates only if -Wdeprecated is enabled. */ fixits_register (loc, upd); } diff --git a/src/location.c b/src/location.c index 62ec9c72..5c567591 100644 --- a/src/location.c +++ b/src/location.c @@ -400,6 +400,8 @@ caret_set_column (int col) void location_caret (location loc, const char *style, FILE *out) { + if (!(feature_flag & feature_caret)) + return; if (!loc.start.line) return; if (!caret_set_file (loc.start.file)) @@ -486,6 +488,8 @@ location_caret (location loc, const char *style, FILE *out) void location_caret_suggestion (location loc, const char *s, FILE *out) { + if (!(feature_flag & feature_caret)) + return; const char *style = "fixit-insert"; fprintf (out, " | %*s", loc.start.column - 1 - caret_info.skip diff --git a/src/location.h b/src/location.h index ccb42e3c..dcb594fb 100644 --- a/src/location.h +++ b/src/location.h @@ -126,12 +126,12 @@ void caret_init (void); left-over by the usage of location_caret. */ void caret_free (void); -/* Quote the line containing LOC onto OUT. Highlight the part of LOC - with the color STYLE. */ +/* If -fcaret is enabled, quote the line containing LOC onto OUT. + Highlight the part of LOC with the color STYLE. */ void location_caret (location loc, const char* style, FILE *out); -/* Display a suggestion of replacement for LOC with S. To call after - location_caret. */ +/* If -fcaret is enabled, display a suggestion of replacement for LOC + with S. To call after location_caret. */ void location_caret_suggestion (location loc, const char *s, FILE *out); /* Return -1, 0, 1, depending whether a is before, equal, or