This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-10-11
[Moved to DR at the November, 2014 meeting.]
Return type deduction from areturn statement with noexpression is described in 9.2.9.7 [dcl.spec.auto] paragraph 7as follows:
When a variable declared using a placeholder type is initialized, or areturn statement occurs in a function declared with a return typethat contains a placeholder type, the deduced return type or variable typeis determined from the type of its initializer. In the case ofareturn with no operand, the initializer is considered tobevoid(). LetT be the declared type of the variable orreturn type of the function. If the placeholder istheautotype-specifier, the deduced type is determinedusing the rules for template argument deduction. If the deduction is forareturn statement and the initializer isabraced-init-list (9.5.5 [dcl.init.list]), the program isill-formed. Otherwise, obtainP fromT by replacing theoccurrences ofauto with either a new invented type templateparameterU or, if the initializer is abraced-init-list,withstd::initializer_list<U>. Deduce a value forUusing the rules of template argument deduction from a function call(13.10.3.2 [temp.deduct.call]), whereP is a function templateparameter type and the initializer is the corresponding argument.
However, this does not work: the deduction for an argument ofvoid() would give a parameter type ofvoid andbe ill-formed. It would be better simply to say that the deduced typein this case isvoid.
In a related example, consider
decltype(auto) f(void *p) { return *p; }
This is presumably an error becausedecltype(*p) would bevoid&, which is ill-formed. Perhaps this case should bementioned explicitly.
Notes from the June, 2014 meeting:
The last part of the issue is not a defect, because the unary* operator requires its operand to be a pointer to an objector function type, andvoid is neither, so the expression isill-formed and deduction does not occur for that case.
It was also observed during the discussion that the same deductionproblem occurs when returning an expression of typevoid aswhen the expression is omitted, so the resolution should cover bothcases.
Proposed resolution (June, 2014):
Change 9.2.9.7 [dcl.spec.auto] paragraph 7 as follows:
When a variable declared using a placeholder type is initialized,or areturn statement occurs in a function declared with a returntype that contains a placeholder type, the deduced return type orvariable type is determined from the type of its initializer. Inthe case of areturn with no operandor with an operandof typevoid, theinitializerdeclaredreturn type shall beauto and the deduced return type isvoidconsidered tobevoid().LetOtherwise,letT be the declared type...