| 1 |
/* Example of fix-it hints that add #include directives, |
| 2 |
adding them after a pre-existing #include. */ |
| 3 |
|
| 4 |
/* { dg-options "-fdiagnostics-generate-patch" } */ |
| 5 |
|
| 6 |
/* This is padding (to avoid the generated patch containing DejaGnu |
| 7 |
directives). */ |
| 8 |
|
| 9 |
#include "empty.h" |
| 10 |
|
| 11 |
namespace std |
| 12 |
{ |
| 13 |
extern int sprintf (char *dst, const char *format, ...); |
| 14 |
}; |
| 15 |
|
| 16 |
void test (void) |
| 17 |
{ |
| 18 |
std::string s ("hello world"); // { dg-error ".string. is not a member of .std." } |
| 19 |
// { dg-message ".std::string. is defined in header .<string>.; this is probably fixable by adding .#include <string>." "" { target *-*-* } .-1 } |
| 20 |
|
| 21 |
std::cout << 10; // { dg-error ".cout. is not a member of .std." } |
| 22 |
// { dg-message ".std::cout. is defined in header .<iostream>.; this is probably fixable by adding .#include <iostream>." "" { target *-*-* } .-1 } |
| 23 |
} |
| 24 |
|
| 25 |
/* Same again, to test idempotency of the added "#include" fix-it. */ |
| 26 |
|
| 27 |
void test_2 (void) |
| 28 |
{ |
| 29 |
std::string s ("hello again"); // { dg-error ".string. is not a member of .std." } |
| 30 |
// { dg-message ".std::string. is defined in header .<string>.; this is probably fixable by adding .#include <string>." "" { target *-*-* } .-1 } |
| 31 |
|
| 32 |
std::cout << 10; // { dg-error ".cout. is not a member of .std." } |
| 33 |
// { dg-message ".std::cout. is defined in header .<iostream>.; this is probably fixable by adding .#include <iostream>." "" { target *-*-* } .-1 } |
| 34 |
} |
| 35 |
|
| 36 |
/* Verify the output from -fdiagnostics-generate-patch. |
| 37 |
We expect the patch to begin with a header, containing this |
| 38 |
source filename, via an absolute path. |
| 39 |
Given the path, we can only capture it via regexps. */ |
| 40 |
/* { dg-regexp "\\-\\-\\- .*" } */ |
| 41 |
/* { dg-regexp "\\+\\+\\+ .*" } */ |
| 42 |
|
| 43 |
/* Verify the hunks within the patch. |
| 44 |
Use #if 0/#endif rather than comments, to allow the text to contain |
| 45 |
a comment. |
| 46 |
We expect a "#include <string>" and "#include <iostream>" to each have been |
| 47 |
added once, immediately below the last #include. */ |
| 48 |
#if 0 |
| 49 |
{ dg-begin-multiline-output "" } |
| 50 |
@@ -7,6 +7,8 @@ |
| 51 |
directives). */ |
| 52 |
|
| 53 |
#include "empty.h" |
| 54 |
+#include <string> |
| 55 |
+#include <iostream> |
| 56 |
|
| 57 |
namespace std |
| 58 |
{ |
| 59 |
{ dg-end-multiline-output "" } |
| 60 |
#endif |