Title
trailing-return-type and point of declaration
Status
nad
Section
6.4.2 [basic.scope.pdecl]
Submitter
Jason Merrill

Created on 2011-12-20.00:00:00 last changed 16 months ago

Messages

Date: 2012-02-15.00:00:00

Rationale (February, 2012):

This is a request for an extension to the language and is thus more appropriately addressed by EWG.

EWG 2022-11-11

This is a breaking change whose benefits and trade-offs need to be carefully analyzed.

Date: 2022-11-20.07:54:16

This seems like it should be well-formed:

    template <class T> T list(T x);

    template <class H, class ...T>
    auto list(H h, T ...args) -> decltype(list(args...));

    auto list3 = list(1, 2, 3);

but it isn't, because the second list isn't in scope in its own trailing-return-type; the point of declaration is after the declarator, which includes the trailing-return-type. And since int has no associated namespaces, the call in the return type only sees the first list. G++, EDG and Clang all reject the testcase on this basis.

But this seems like a natural pattern for writing variadic function templates, and we could support it by moving the point of declaration to the ->. This would mean having to deal with a function that only has a placeholder for a return type, but I think we can handle that.

History
Date User Action Args
2022-11-23 23:14:34adminsetstatus: extension -> nad
2012-02-27 00:00:00adminsetmessages: + msg3861
2012-02-27 00:00:00adminsetstatus: open -> extension
2011-12-20 00:00:00admincreate