view gcc/testsuite/gcc.dg/missing-header-fixit-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* Example of a fix-it hint that adds a #include directive,
   adding them to the top of the file, given that there is no
   pre-existing #include.  */

/* This is padding (to avoid the generated patch containing DejaGnu
   directives).  */

/* { dg-options "-fdiagnostics-generate-patch" } */

void test (int i, int j)
{
  printf ("%i of %i\n", i, j); /* { dg-warning "implicit declaration" } */
  /* { dg-message "include '<stdio.h>' or provide a declaration of 'printf'" "" { target *-*-* } .-1 } */
}

/* Verify the output from -fdiagnostics-generate-patch.
   We expect the patch to begin with a header, containing this
   source filename, via an absolute path.
   Given the path, we can only capture it via regexps.  */
/* { dg-regexp "\\-\\-\\- .*" } */
/* { dg-regexp "\\+\\+\\+ .*" } */
/* Use #if 0/#endif rather than comments, to allow the text to contain
   a comment.  */
#if 0
{ dg-begin-multiline-output "" }
@@ -1,3 +1,4 @@
+#include <stdio.h>
 /* Example of a fix-it hint that adds a #include directive,
    adding them to the top of the file, given that there is no
    pre-existing #include.  */
{ dg-end-multiline-output "" }
#endif

/* FIXME: should we attempt to skip leading comments when determining the
   insertion location?
   Similarly, should we attempt to be within single-inclusion guards, etc?  */