PETSC_NODISCARD#
Mark the return value of a function as non-discardable Not available in Fortran
Notes#
Hints to the compiler that the return value of a function must be captured. A diagnostic may (but is not required to) be emitted if the value is discarded. It is safe to use this in both C and C++ source files.
Example Usage#
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'
See Also#
Level#
beginner
Location#
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages