# PETSC_NODISCARD
Mark the return value of a function as non-discardable 
## Notes
Hints to the compiler that the return value of a function must be captured. A diagnostic may
(but is not required) be emitted if the value is discarded. It is safe to use this in C
and C++ source files.


## Fortran Notes
Not available in Fortran


## Example Usage
```none
  class Foo
  {
    int x;

  public:
    PETSC_NODISCARD Foo(int y) : x(y) { }
  };

  PETSC_NODISCARD int factorial(int n)
  {
    return n <= 1 ? 1 : (n * factorial(n - 1));
  }

  auto x = factorial(10); // OK, capturing return value
  factorial(10);          // Warning: ignoring return value of function declared 'nodiscard'

  auto f = Foo(x); // OK, capturing constructed object
  Foo(x);          // Warning: Ignoring temporary created by a constructor declared 'nodiscard'
```



## Developer Notes
It is highly recommended if not downright required that any PETSc routines written in C++
returning a PetscErrorCode be marked `PETSC_NODISCARD`. Ignoring the return value of PETSc
routines is not supported; unhandled errors may leave PETSc in an unrecoverable state.




## See Also
 `PETSC_NULLPTR`, `PETSC_CONSTEXPR_14`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscmacros.h.html#PETSC_NODISCARD">include/petscmacros.h</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscmacros.h)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
