C++17 introduces [[nodiscard]] attribute to let the compiler deduce that the return value of a function or method must be handled by a properly assigned value. The attribute simply produces compilation warning when the flagged function is invoked with its return value bypassed.
#include <cstring>
[[nodiscard ( Deallocate the char* in callers scope using
delete[]!")]]
char getLog() {
char* log
new char[100];
strcpy(log, "[INFO]: Hello World!");
return log;
}
int main() {
getLog(); // ERROR: attribute produces
// compile time warning
auto log = getLog(); // OK
delete[] log;
return 0;
}