Can a C++ function be declared such that the return value cannot be ignored?
<p>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 a class with a <code>private</code> (or in C++11, <code>delete</code>d) <code>operator void()</code> to try to catch the implicit conversion to void when a return value is unused.</p>

<p>Here's an example program:</p>

<pre><code>class Unignorable {
    operator void();
};

Unignorable foo()
{
    return Unignorable();
}

int main()
{
    foo();
    return 0;
}
</code></pre>

<p>Unfortunately, my compiler (clang-703.0.31) says:</p>

<pre><code>test.cpp:2:5: warning: conversion function converting 'Unignorable' to 'void' will never be used
    operator void();
    ^
</code></pre>

<p>and doesn't raise any error or warning on the call to <code>foo()</code>. So, that won't work. Is there any other way to do this? Answers specific to C++11 or C++14 or later would be fine.</p>