atomgalaxy/wg21-cust-points

Add: two template-heads is a cursed parse (as per Sean)

Opened this issue · 1 comments

@seanbax writes:


Yesterday I was favoring separating the template parameters into separate lists for the class and function, but I started doing some work this morning and realized that would be a cursed parse. Very hard to distinguish that usage from an extraneous template-header scenario:

template<typename T>
extern void func<T>(T x, T* p);   // uses one template-head

template<typename T1>
template<typename T2>
virtual void cpo<T1>(T2 x);  // uses two template-heads, yet looks exactly the same except for the virtual keyword.

Supporting that syntax would require matching the virtual keyword, knowing that we're in a namespace, and advancing the header index when parsing the temp-id cpo<T1>, with the anticipation that the next token is a (. This gets into modifications of this paragraph:
https://eel.is/c++draft/temp.expl.spec#8

Not a show-stopper by any means, but I'm against adding novel rules to the already super difficult act of balancing template heads and argument lists.


Add this to the discussion

Would this parse be even more difficult if we replaced the virtual keyword with a trailling context-sensitive keyword?
You wouldn't know it was a customisable function declaration then until the very end of the declaration line.