xref: /petsc/src/sys/tests/linter/testReferences.c (revision 21e3ffae2f3b73c0bd738cf6d0a809700fc04bb0)
1 /* for access to private viewer members */
2 #include <petsc/private/viewerimpl.h>
3 
4 /* forward declare */
5 void extractFunc(PetscViewer, void **);
6 
7 PetscErrorCode testOutOfLineReference(PetscViewer v, PetscViewer v2)
8 {
9   /* linter should be able to connect all of these to v */
10   void  *foo  = v->data, *bar, *baz, *blop;
11   void **blip = &v->data;
12 
13   bar  = v->data;
14   blop = blip[0];
15   extractFunc(v, &baz);
16 
17   /* incorrect */
18   PetscValidPointer(foo, -1);
19   PetscValidPointer(bar, -2);
20   PetscValidPointer(baz, -3);
21   PetscValidPointer((void *)v->data, -4);
22   PetscValidPointer(*blip, -5);
23   PetscValidPointer(blop, -6);
24 
25   /* correct */
26   PetscValidPointer(foo, 1);
27   PetscValidPointer(bar, 1);
28   PetscValidPointer(baz, 1);
29   PetscValidPointer((void *)v->data, 1);
30   PetscValidPointer(*blip, 1);
31   PetscValidPointer(blop, 1);
32   return 0;
33 }
34