| Doc. No.: | N4309 |
|---|---|
| Date: | 2014-11-17 |
| Project: | Programming Language C++, Evolution Working Group |
| Reply To: | Michael Price <michael.b.price.dev@gmail.com> |
Proposes to allow auto and declspec(auto)
as the type-specifiers for the return type of explicitly-defaulted
and deleted special member functions. It seems this case was left out of
N3638.
Paragraph 7.1.6.4, clause 2 of the draft standard (N4141) states:
The placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such a declarator is valid. If the function declarator includes a trailing-return-type (8.3.5), that specifies the declared return type of the function. If the declared return type of the function contains a placeholder type, the return type of the function is deduced from
returnstatements in the body of the function, if any.
This wording allows the usage of auto or declspec(auto)
in a function definition, only if there is a trailing return type or a
function body that contains at least one return
statement that can be used to deduce the return type. This proposal would
allow the placeholder type-specifiers to be valid for special member functions
that are explicitly-defaulted or deleted.
struct VersionOne
{
VersionOne() = default;
~VersionOne() = default;
VersionOne(const VersionOne&) = default;
VersionOne(VersionOne&&) = default;
VersionOne& operator=(const VersionOne&) = default;
VersionOne& operator=(VersionOne&&) = default;
};
// For some reason, the author decided that I wanted non-default
// copy operations and thought it would be nice to throw in 'auto'.
//
struct VersionTwo
{
VersionTwo() = default;
~VersionTwo() = default;
VersionTwo(const VersionTwo&) { /* ... */ }
VersionTwo(VersionTwo&&) = default;
auto operator=(const VersionTwo&) { /* ... */ return *this; }
auto operator=(VersionTwo&&) = default; // Currently an error!
};
This paper is looking for guidance on whether this feature should be pursued. It provides no wording.