Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-error-with-note.cc

raw
1 /* C++ example of emitting an error with an associated note.
2
3 Intended output is similar to:
4
5 PATH/test-error-with-note.c:17:8: error: can't find 'foo'
6 17 | PRINT "hello world!";
7 | ^~~~~~~~~~~~
8 PATH/test-error-with-note.c:17:8: note: have you looked behind the couch?
9
10 along with the equivalent in SARIF. */
11
12 #include "libgdiagnostics++.h"
13
14 /*
15 _________111111111122
16 123456789012345678901
17 PRINT "hello world!";
18 */
19 const int line_num = __LINE__ - 2;
20
21 int
22 main ()
23 {
24 libgdiagnostics::manager mgr;
25
26 auto file = mgr.new_file (__FILE__, "c");
27
28 mgr.add_text_sink (stderr, DIAGNOSTIC_COLORIZE_IF_TTY);
29
30 auto loc_start = mgr.new_location_from_file_line_column (file, line_num, 8);
31 auto loc_end = mgr.new_location_from_file_line_column (file, line_num, 19);
32 auto loc_range = mgr.new_location_from_range (loc_start,
33 loc_start,
34 loc_end);
35
36 libgdiagnostics::group g (mgr);
37
38 auto err (mgr.begin_diagnostic (DIAGNOSTIC_LEVEL_ERROR));
39 err.set_location (loc_range);
40 err.finish ("can't find %qs", "foo");
41
42 auto note = mgr.begin_diagnostic (DIAGNOSTIC_LEVEL_NOTE);
43 note.set_location (loc_range);
44 note.finish ("have you looked behind the couch?");
45
46 return 0;
47 };
48
49 /* Verify the output from the text sink.
50 { dg-regexp "\[^\n\r\]+test-error-with-note.cc:17:8: error: can't find 'foo'" }
51 { dg-begin-multiline-output "" }
52 17 | PRINT "hello world!";
53 | ^~~~~~~~~~~~
54 { dg-end-multiline-output "" }
55 { dg-regexp "\[^\n\r\]+test-error-with-note.cc:17:8: note: have you looked behind the couch\\\?" } */