diff options
Diffstat (limited to 'gcc/testsuite')
14 files changed, 513 insertions, 19 deletions
diff --git a/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-highlight-colors.C b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-highlight-colors.C new file mode 100644 index 0000000..1260345 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-highlight-colors.C @@ -0,0 +1,34 @@ +/* Verify that colorization affects both text within diagnostic messages + and underlined ranges of quoted source, and that the types we use + match up between them. + Also implicitly verify that -fdiagnostics-show-highlight-colors is + on by default. */ + +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-color=always" } */ + +struct s {}; +struct t {}; +typedef struct s S; +typedef struct t T; + +extern S callee_4a (void); +extern T callee_4b (void); + +int test_4 (void) +{ + return callee_4a () + callee_4b (); + + /* { dg-begin-multiline-output "" } + [m[K [01;31m[Kerror: [m[Kno match for '[01m[Koperator+[m[K' (operand types are '[01m[K[01;32m[KS[m[K' {aka '[01m[K[01;32m[Ks[m[K'}[m[K and '[01m[K[01;34m[KT[m[K' {aka '[01m[K[01;34m[Kt[m[K'}[m[K) + { dg-end-multiline-output "" } */ + + /* { dg-begin-multiline-output "" } + return [01;32m[Kc[m[K[01;32m[Ka[m[K[01;32m[Kl[m[K[01;32m[Kl[m[K[01;32m[Ke[m[K[01;32m[Ke[m[K[01;32m[K_[m[K[01;32m[K4[m[K[01;32m[Ka[m[K[01;32m[K [m[K[01;32m[K([m[K[01;32m[K)[m[K [01;31m[K+[m[K [01;34m[Kc[m[K[01;34m[Ka[m[K[01;34m[Kl[m[K[01;34m[Kl[m[K[01;34m[Ke[m[K[01;34m[Ke[m[K[01;34m[K_[m[K[01;34m[K4[m[K[01;34m[Kb[m[K[01;34m[K [m[K[01;34m[K([m[K[01;34m[K)[m[K; + [01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K [01;31m[K^[m[K [01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K + [01;32m[K|[m[K [01;34m[K|[m[K + [01;32m[KS {aka s}[m[K [01;34m[KT {aka t}[m[K + { dg-end-multiline-output "" } */ + + /* { dg-prune-output "In function" } */ + /* { dg-prune-output "bad-binary-ops-highlight-colors.C" } */ +} diff --git a/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C new file mode 100644 index 0000000..5b1b65a --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/bad-binary-ops-no-highlight-colors.C @@ -0,0 +1,29 @@ +/* Verify that -fno-diagnostics-show-highlight-colors works. */ +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-color=always -fno-diagnostics-show-highlight-colors" } */ + +struct s {}; +struct t {}; +typedef struct s S; +typedef struct t T; + +extern S callee_4a (void); +extern T callee_4b (void); + +int test_4 (void) +{ + return callee_4a () + callee_4b (); + + /* { dg-begin-multiline-output "" } + [m[K [01;31m[Kerror: [m[Kno match for '[01m[Koperator+[m[K' (operand types are '[01m[KS[m[K' {aka '[01m[Ks[m[K'} and '[01m[KT[m[K' {aka '[01m[Kt[m[K'}) + { dg-end-multiline-output "" } */ + + /* { dg-begin-multiline-output "" } + return [32m[Kcallee_4a ()[m[K [01;31m[K+[m[K [34m[Kcallee_4b ()[m[K; + [32m[K~~~~~~~~~~~~[m[K [01;31m[K^[m[K [34m[K~~~~~~~~~~~~[m[K + [32m[K|[m[K [34m[K|[m[K + [32m[KS {aka s}[m[K [34m[KT {aka t}[m[K + { dg-end-multiline-output "" } */ + + /* { dg-prune-output "In function" } */ + /* { dg-prune-output "bad-binary-ops-no-highlight-colors.C" } */ +} diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 88f9b49..b5f8743 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -77,6 +77,7 @@ set plugin_test_list [list \ location-overflow-test-pr100796.c } \ { show_template_tree_color_plugin.c \ show-template-tree-color.C \ + show-template-tree-color-no-highlight-colors.C \ show-template-tree-color-labels.C \ show-template-tree-color-no-elide-type.C } \ { comment_plugin.c comments-1.C } \ diff --git a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C index 462e1bd..75488cb 100644 --- a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C +++ b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-labels.C @@ -15,11 +15,11 @@ void test_1 (vector<double> vec) { fn_1 (vec); /* { dg-begin-multiline-output "" } -could not convert '[01m[Kvec[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;32m[Kint[m[K>[m[K' - fn_1 ([01;31m[Kvec[m[K); - [01;31m[K^~~[m[K - [01;31m[K|[m[K - [01;31m[Kvector<double>[m[K +could not convert '[01m[Kvec[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;34m[Kint[m[K>[m[K' + fn_1 ([01;32m[Kv[m[K[01;32m[Ke[m[K[01;32m[Kc[m[K); + [01;32m[K^[m[K[01;32m[K~[m[K[01;32m[K~[m[K + [01;32m[K|[m[K + [01;32m[Kvector<double>[m[K { dg-end-multiline-output "" } */ // TODO: we don't yet highlight the mismatching part with color } @@ -28,11 +28,11 @@ void test_2 (const map<int, double> &m) { fn_2 (m); /* { dg-begin-multiline-output "" } -could not convert '[01m[Km[m[K' from '[01m[Kmap<[...],[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<[...],[01;32m[Kint[m[K>[m[K' - fn_2 ([01;31m[Km[m[K); - [01;31m[K^[m[K - [01;31m[K|[m[K - [01;31m[Kmap<[...],double>[m[K +could not convert '[01m[Km[m[K' from '[01m[Kmap<[...],[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<[...],[01;34m[Kint[m[K>[m[K' + fn_2 ([01;32m[Km[m[K); + [01;32m[K^[m[K + [01;32m[K|[m[K + [01;32m[Kmap<[...],double>[m[K { dg-end-multiline-output "" } */ // TODO: we don't yet highlight the mismatching part with color } diff --git a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-elide-type.C b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-elide-type.C index cab0359..758a77f 100644 --- a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-elide-type.C +++ b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-elide-type.C @@ -15,16 +15,16 @@ void test () { fn_1 (vector<double> ()); /* { dg-begin-multiline-output "" } -could not convert '[01m[Kvector<double>()[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;32m[Kint[m[K>[m[K' +could not convert '[01m[Kvector<double>()[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;34m[Kint[m[K>[m[K' vector< - [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + [[01;32m[Kdouble[m[K != [01;34m[Kint[m[K]> { dg-end-multiline-output "" } */ fn_2 (map<int, double>()); /* { dg-begin-multiline-output "" } -could not convert '[01m[Kmap<int, double>()[m[K' from '[01m[Kmap<int,[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<int,[01;32m[Kint[m[K>[m[K' +could not convert '[01m[Kmap<int, double>()[m[K' from '[01m[Kmap<int,[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<int,[01;34m[Kint[m[K>[m[K' map< int, - [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + [[01;32m[Kdouble[m[K != [01;34m[Kint[m[K]> { dg-end-multiline-output "" } */ } diff --git a/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-highlight-colors.C b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-highlight-colors.C new file mode 100644 index 0000000..5329f90 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/show-template-tree-color-no-highlight-colors.C @@ -0,0 +1,32 @@ +/* Verify colorization of the output of -fdiagnostics-show-template-tree, + and within the %H and %I format codes, but with + -fno-diagnostics-show-highlight-colors. + + Doing so requires a plugin; see the comments in the plugin for the + rationale. */ + +// { dg-options "-fdiagnostics-show-template-tree -fdiagnostics-color=always -fno-diagnostics-show-highlight-colors" } + +template<typename> struct vector {}; +template<typename, typename> struct map {}; + +void fn_1(vector<int>); +void fn_2(map<int, int>); + +void test () +{ + fn_1 (vector<double> ()); + /* { dg-begin-multiline-output "" } +could not convert '[01m[Kvector<double>()[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;32m[Kint[m[K>[m[K' + vector< + [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + { dg-end-multiline-output "" } */ + + fn_2 (map<int, double>()); + /* { dg-begin-multiline-output "" } +could not convert '[01m[Kmap<int, double>()[m[K' from '[01m[Kmap<[...],[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<[...],[01;32m[Kint[m[K>[m[K' + map< + [...], + [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + { dg-end-multiline-output "" } */ +} diff --git a/gcc/testsuite/g++.dg/plugin/show-template-tree-color.C b/gcc/testsuite/g++.dg/plugin/show-template-tree-color.C index eb99a3e..cc60ba6 100644 --- a/gcc/testsuite/g++.dg/plugin/show-template-tree-color.C +++ b/gcc/testsuite/g++.dg/plugin/show-template-tree-color.C @@ -15,16 +15,16 @@ void test () { fn_1 (vector<double> ()); /* { dg-begin-multiline-output "" } -could not convert '[01m[Kvector<double>()[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;32m[Kint[m[K>[m[K' +could not convert '[01m[Kvector<double>()[m[K' from '[01m[Kvector<[01;32m[Kdouble[m[K>[m[K' to '[01m[Kvector<[01;34m[Kint[m[K>[m[K' vector< - [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + [[01;32m[Kdouble[m[K != [01;34m[Kint[m[K]> { dg-end-multiline-output "" } */ fn_2 (map<int, double>()); /* { dg-begin-multiline-output "" } -could not convert '[01m[Kmap<int, double>()[m[K' from '[01m[Kmap<[...],[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<[...],[01;32m[Kint[m[K>[m[K' +could not convert '[01m[Kmap<int, double>()[m[K' from '[01m[Kmap<[...],[01;32m[Kdouble[m[K>[m[K' to '[01m[Kmap<[...],[01;34m[Kint[m[K>[m[K' map< [...], - [[01;32m[Kdouble[m[K != [01;32m[Kint[m[K]> + [[01;32m[Kdouble[m[K != [01;34m[Kint[m[K]> { dg-end-multiline-output "" } */ } diff --git a/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-1.C b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-1.C new file mode 100644 index 0000000..dd41b08 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-1.C @@ -0,0 +1,200 @@ +// Test of -Wformat for GCC-specific formats +// Copy of gcc.dg/format/gcc_diag-10.c, with class pp_element added. +// { dg-do compile } +// { dg-options "-Wformat" } + +/* Magic identifiers must be set before the attribute is used. */ + +typedef long long __gcc_host_wide_int__; + +typedef struct location_s +{ + const char *file; + int line; +} location_t; + +union tree_node; +typedef union tree_node *tree; + +/* Define gimple as a dummy type. The typedef must be provided for + the C test to find the symbol. */ +typedef struct gimple gimple; + +/* Likewise for gimple. */ +typedef struct cgraph_node cgraph_node; + +/* Likewise for diagnostic_event_id_t. */ +typedef struct diagnostic_event_id_t diagnostic_event_id_t; + +namespace pp_markup { class element; } +typedef pp_markup::element pp_element; + +#define FORMAT(kind) __attribute__ ((format (__gcc_## kind ##__, 1, 2))) + +void diag (const char*, ...) FORMAT (diag); +void cdiag (const char*, ...) FORMAT (cdiag); +void tdiag (const char*, ...) FORMAT (tdiag); +void cxxdiag (const char*, ...) FORMAT (cxxdiag); +void dump (const char*, ...) FORMAT (dump_printf); + +void test_diag (tree t, gimple *gc, diagnostic_event_id_t *event_id_ptr, + pp_element *elem) +{ + diag ("%<"); /* { dg-warning "unterminated quoting directive" } */ + diag ("%>"); /* { dg-warning "unmatched quoting directive " } */ + diag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ + + diag ("%G", gc); /* { dg-warning "format" } */ + diag ("%K", t); /* { dg-warning "format" } */ + diag ("%@", event_id_ptr); + + diag ("%R"); /* { dg-warning "unmatched color reset directive" } */ + diag ("%r", ""); /* { dg-warning "unterminated color directive" } */ + diag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ + diag ("%r%R", ""); + diag ("%r%r%R", "", ""); + diag ("%r%R%r%R", "", ""); + + diag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ + diag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ + diag ("%<%r%R%>", ""); + + diag ("%e", elem); + diag ("%e", 42); /* { dg-warning "format" } */ +} + +void test_cdiag (tree t, gimple *gc) +{ + cdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */ + cdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */ + cdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ + + cdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ + cdiag ("%E", t); + cdiag ("%F", t); /* { dg-warning ".F. conversion used unquoted" } */ + cdiag ("%G", gc); /* { dg-warning "format" } */ + cdiag ("%K", t); /* { dg-warning "format" } */ + + cdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ + cdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ + cdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ + cdiag ("%r%R", ""); + cdiag ("%r%r%R", "", ""); + cdiag ("%r%R%r%R", "", ""); + + cdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ + cdiag ("%V", t); /* { dg-warning ".V. conversion used unquoted" } */ + + cdiag ("%<%D%>", t); + cdiag ("%<%E%>", t); + cdiag ("%<%F%>", t); + cdiag ("%<%G%>", gc); /* { dg-warning "format" } */ + cdiag ("%<%K%>", t); /* { dg-warning "format" } */ + + cdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ + cdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ + cdiag ("%<%r%R%>", ""); + + cdiag ("%<%T%>", t); + cdiag ("%<%V%>", t); + + cdiag ("%<%qD%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ + cdiag ("%<%qE%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ + cdiag ("%<%qT%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ +} + +void test_tdiag (tree t, gimple *gc) +{ + tdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */ + tdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */ + tdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ + + tdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ + tdiag ("%E", t); + tdiag ("%G", gc); /* { dg-warning "format" } */ + tdiag ("%K", t); /* { dg-warning "format" } */ + + tdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ + tdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ + tdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ + tdiag ("%r%R", ""); + tdiag ("%r%R", ""); + tdiag ("%r%r%R", "", ""); + tdiag ("%r%R%r%R", "", ""); + + tdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ + + tdiag ("%<%D%>", t); + tdiag ("%<%E%>", t); + tdiag ("%<%G%>", gc); /* { dg-warning "format" } */ + tdiag ("%<%K%>", t); /* { dg-warning "format" } */ + + tdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ + tdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ + tdiag ("%<%r%R%>", ""); + + tdiag ("%<%T%>", t); + + tdiag ("%<%qD%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ + tdiag ("%<%qE%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ + tdiag ("%<%qT%>", t); /* { dg-warning ".q. flag used within a quoted sequence" } */ +} + +void test_cxxdiag (tree t, gimple *gc) +{ + cxxdiag ("%A", t); /* { dg-warning ".A. conversion used unquoted" } */ + cxxdiag ("%D", t); /* { dg-warning ".D. conversion used unquoted" } */ + cxxdiag ("%E", t); + cxxdiag ("%F", t); /* { dg-warning ".F. conversion used unquoted" } */ + cxxdiag ("%G", gc); /* { dg-warning "format" } */ + cxxdiag ("%K", t); /* { dg-warning "format" } */ + + cxxdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */ + cxxdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */ + cxxdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ + cxxdiag ("%r%R", ""); + cxxdiag ("%r%R", ""); + cxxdiag ("%r%r%R", "", ""); + cxxdiag ("%r%R%r%R", "", ""); + + cxxdiag ("%S", t); /* { dg-warning ".S. conversion used unquoted" } */ + cxxdiag ("%T", t); /* { dg-warning ".T. conversion used unquoted" } */ + cxxdiag ("%V", t); /* { dg-warning ".V. conversion used unquoted" } */ + cxxdiag ("%X", t); /* { dg-warning ".X. conversion used unquoted" } */ + + cxxdiag ("%<%A%>", t); + cxxdiag ("%<%D%>", t); + cxxdiag ("%<%E%>", t); + cxxdiag ("%<%F%>", t); + cxxdiag ("%<%R%>"); /* { dg-warning "unmatched color reset" } */ + cxxdiag ("%<%r%R%>", ""); + cxxdiag ("%<%S%>", t); + cxxdiag ("%<%T%>", t); + cxxdiag ("%<%V%>", t); + cxxdiag ("%<%X%>", t); +} + +void test_dump (tree t, gimple *stmt, cgraph_node *node) +{ + dump ("%<"); /* { dg-warning "unterminated quoting directive" } */ + dump ("%>"); /* { dg-warning "unmatched quoting directive " } */ + dump ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */ + + dump ("%R"); /* { dg-warning "unmatched color reset directive" } */ + dump ("%r", ""); /* { dg-warning "unterminated color directive" } */ + dump ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */ + dump ("%r%R", ""); + dump ("%r%r%R", "", ""); + dump ("%r%R%r%R", "", ""); + + dump ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */ + dump ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */ + dump ("%<%r%R%>", ""); + + dump ("%E", stmt); + dump ("%T", t); + dump ("%G", stmt); + dump ("%C", node); + dump ("%f", 1.0); + dump ("%4.2f", 1.0); /* { dg-warning "format" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-2.C b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-2.C new file mode 100644 index 0000000..0cce53c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-2.C @@ -0,0 +1,52 @@ +// Test of -Wformat for subclasses of pp_element +// { dg-do compile } +// { dg-options "-Wformat" } + +/* Magic identifiers must be set before the attribute is used. */ + +typedef long long __gcc_host_wide_int__; + +typedef struct location_s +{ + const char *file; + int line; +} location_t; + +union tree_node; +typedef union tree_node *tree; + +/* Define gimple as a dummy type. The typedef must be provided for + the C test to find the symbol. */ +typedef struct gimple gimple; + +/* Likewise for gimple. */ +typedef struct cgraph_node cgraph_node; + +/* Likewise for diagnostic_event_id_t. */ +typedef struct diagnostic_event_id_t diagnostic_event_id_t; + +namespace pp_markup { +class element +{ +}; +} // namespace pp_markup +typedef pp_markup::element pp_element; + +#define FORMAT(kind) __attribute__ ((format (__gcc_## kind ##__, 1, 2))) + +void diag (const char*, ...) FORMAT (diag); + +class sub_element : public pp_element +{ +}; + +class sub_sub_element : public sub_element +{ +}; + +void test_diag () +{ + sub_element e1; + sub_sub_element e2; + diag ("%e %e", &e1, &e2); +} diff --git a/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-3.C b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-3.C new file mode 100644 index 0000000..f474778 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wformat-gcc_diag-3.C @@ -0,0 +1,54 @@ +// Test of -Wformat for subclasses of pp_element +// { dg-do compile } +// { dg-options "-Wformat" } + +union tree_node; +typedef union tree_node *tree; +class rich_location; +class pretty_printer; + +namespace pp_markup { +class element {}; + +} // namespace pp_markup + +typedef pp_markup::element pp_element; + +extern void error_at (rich_location *, const char *, ...) + __attribute__ ((__format__ (__gcc_cdiag__, 2, 3), + __nonnull__ (2))); + +namespace highlight_colors { + +extern const char *const lhs; +extern const char *const rhs; + +} // namespace highlight_colors + +namespace pp_markup { + +class element_quoted_type : public element +{ +public: + element_quoted_type (tree type, const char *highlight_color) + : m_type (type), + m_highlight_color (highlight_color) + { + } +private: + tree m_type; + const char *m_highlight_color; +}; + +} + +void +binary_op_error (rich_location *richloc, const char *opname, + tree type0, tree type1) +{ + pp_markup::element_quoted_type element_0 (type0, highlight_colors::lhs); + pp_markup::element_quoted_type element_1 (type1, highlight_colors::rhs); + error_at (richloc, + "invalid operands to binary %s (have %e and %e)", + opname, &element_0, &element_1); +} diff --git a/gcc/testsuite/gcc.dg/bad-binary-ops-highlight-colors.c b/gcc/testsuite/gcc.dg/bad-binary-ops-highlight-colors.c new file mode 100644 index 0000000..efbcdf3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bad-binary-ops-highlight-colors.c @@ -0,0 +1,35 @@ +/* Verify that colorization affects both text within diagnostic messages + and underlined ranges of quoted source, and that the types we use + match up between them. + Also implicitly verify that -fdiagnostics-show-highlight-colors is + on by default. */ + +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-color=always" } */ + +struct s {}; +struct t {}; +typedef struct s S; +typedef struct t T; + +extern S callee_4a (void); +extern T callee_4b (void); + +int test_4 (void) +{ + return callee_4a () + callee_4b (); + + /* { dg-begin-multiline-output "" } + [m[K [01;31m[Kerror: [m[Kinvalid operands to binary + (have '[01m[K[01;32m[KS[m[K' {aka [m[K'[01m[K[01;32m[Kstruct s[m[K'}[m[K and '[01m[K[01;34m[KT[m[K' {aka [m[K'[01m[K[01;34m[Kstruct t[m[K'}[m[K) + { dg-end-multiline-output "" } */ + + /* { dg-begin-multiline-output "" } + return [01;32m[Kc[m[K[01;32m[Ka[m[K[01;32m[Kl[m[K[01;32m[Kl[m[K[01;32m[Ke[m[K[01;32m[Ke[m[K[01;32m[K_[m[K[01;32m[K4[m[K[01;32m[Ka[m[K[01;32m[K [m[K[01;32m[K([m[K[01;32m[K)[m[K [01;31m[K+[m[K [01;34m[Kc[m[K[01;34m[Ka[m[K[01;34m[Kl[m[K[01;34m[Kl[m[K[01;34m[Ke[m[K[01;34m[Ke[m[K[01;34m[K_[m[K[01;34m[K4[m[K[01;34m[Kb[m[K[01;34m[K [m[K[01;34m[K([m[K[01;34m[K)[m[K; + [01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K[01;32m[K~[m[K [01;31m[K^[m[K [01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K + [01;32m[K|[m[K [01;34m[K|[m[K + [01;32m[K|[m[K [01;34m[KT {aka struct t}[m[K + [01;32m[KS {aka struct s}[m[K + { dg-end-multiline-output "" } */ + + /* { dg-prune-output "In function" } */ + /* { dg-prune-output "bad-binary-ops-highlight-colors.c" } */ +} diff --git a/gcc/testsuite/gcc.dg/bad-binary-ops-no-highlight-colors.c b/gcc/testsuite/gcc.dg/bad-binary-ops-no-highlight-colors.c new file mode 100644 index 0000000..9eb22cb --- /dev/null +++ b/gcc/testsuite/gcc.dg/bad-binary-ops-no-highlight-colors.c @@ -0,0 +1,30 @@ +/* Verify that -fno-diagnostics-show-highlight-colors works. */ +/* { dg-options "-fdiagnostics-show-caret -fdiagnostics-color=always -fno-diagnostics-show-highlight-colors" } */ + +struct s {}; +struct t {}; +typedef struct s S; +typedef struct t T; + +extern S callee_4a (void); +extern T callee_4b (void); + +int test_4 (void) +{ + return callee_4a () + callee_4b (); + + /* { dg-begin-multiline-output "" } + [m[K [01;31m[Kerror: [m[Kinvalid operands to binary + (have '[01m[KS[m[K' {aka [m[K'[01m[Kstruct s[m[K'} and '[01m[KT[m[K' {aka [m[K'[01m[Kstruct t[m[K'}) + { dg-end-multiline-output "" } */ + + /* { dg-begin-multiline-output "" } + return [32m[Kcallee_4a ()[m[K [01;31m[K+[m[K [34m[Kcallee_4b ()[m[K; + [32m[K~~~~~~~~~~~~[m[K [01;31m[K^[m[K [34m[K~~~~~~~~~~~~[m[K + [32m[K|[m[K [34m[K|[m[K + [32m[K|[m[K [34m[KT {aka struct t}[m[K + [32m[KS {aka struct s}[m[K + { dg-end-multiline-output "" } */ + + /* { dg-prune-output "In function" } */ + /* { dg-prune-output "bad-binary-ops-no-highlight-colors.c" } */ +} diff --git a/gcc/testsuite/gcc.dg/format/colors.c b/gcc/testsuite/gcc.dg/format/colors.c new file mode 100644 index 0000000..43484b7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/colors.c @@ -0,0 +1,27 @@ +/* Verify that colorization affects both text within diagnostic messages + and underlined ranges of quoted source, and that the types we use + match up between them. */ + +/* { dg-do compile } */ +/* { dg-options "-Wformat -fdiagnostics-show-caret -fdiagnostics-color=always" } */ + +#include "format.h" + +void test_mismatching_types (const char *msg) +{ + printf("hello %i", msg); + +/* { dg-begin-multiline-output "" } +warning: [m[Kformat '[01m[K[01;32m[K%i[m[K[m[K' expects argument of type '[01m[K[01;32m[Kint[m[K[m[K', but argument 2 has type '[01m[K[01;34m[Kconst char *[m[K[m[K' [[01;35m[K-Wformat=[m[K] + { dg-end-multiline-output "" } */ +/* { dg-begin-multiline-output "" } + printf("hello [01;32m[K%[m[K[01;32m[Ki[m[K", [01;34m[Km[m[K[01;34m[Ks[m[K[01;34m[Kg[m[K); + [01;32m[K~[m[K[01;32m[K^[m[K [01;34m[K~[m[K[01;34m[K~[m[K[01;34m[K~[m[K + [01;32m[K|[m[K [01;34m[K|[m[K + [01;32m[Kint[m[K [01;34m[Kconst char *[m[K + [32m[K%s[m[K + { dg-end-multiline-output "" } */ +} + +/* { dg-prune-output "In function" } */ +/* { dg-prune-output "colors.c" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c index f5c6fc5..44b94da 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.c @@ -41,7 +41,7 @@ show_tree (tree node) return; gcc_rich_location richloc (EXPR_LOCATION (node)); - richloc.add_expr (node, NULL); + richloc.add_expr (node, nullptr, nullptr); if (richloc.get_num_locations () < 2) { |