I\'m trying to determine whether a C++ function can be declared in such a way that the return value cannot be ignored (ideally detected at compile time). I tried to declare
See __attribute__ ((warn_unused_result)).
int foo() __attribute__ ((warn_unused_result)); int foo(){return 123;} int main() { foo(); //compiler warning auto i = foo(); //valid }
Then force the warning to be an error:
clang++ -std=c++1z -Werror="unused-result"