I'm writing some code where the return type of a function is rather complicated. I'd like to make use of auto for deducing from the return type, but that's obviously not possible in a forward declaration. So I was hoping to at least only duplicate the contents of the return statement and do the following,
int q = 5; // veeery complicated type
/* Declaration - the best we can do */
auto f() -> decltype(q);
/* Later, in a different file */
auto f() {
return q;
}
This produces the following error in GCC 7,
error: ambiguating new declaration of ‘auto f()’
note: old declaration ‘int f()’
Of course I could repeat
auto f() -> decltype(q) {
return q;
}
in the definition (which works) but why should I need to when the return type is already uniquely given by the return statement? How is the type of f in my definition ultimately any more ambiguous than int f()?