Confusion with non-type template-name as a simple-type-specifier

57 views
Skip to first unread message

Johannes Schaub

unread,
Oct 15, 2017, 7:46:51 AM10/15/17
to std-dis...@isocpp.org
The following "f(n)" parses as a declaration because "f" is an
ill-formed simple-type-specifier

template<typename T>
void f(T);

int main() {
int n = 0;
{ f(n); }
}

The spec says

"The template-name shall name a class template that is not an
injected-class-name."

I don't know whether this precludes type template template parameters.
But in addition, according to [stmt.ambig]

"Disambiguation precedes parsing, and a statement disambiguated as
a declaration may be an ill-formed declaration."

Therefore, the "shall name.." does not need to stop "f(n);" from being
a declaration. I recommend rewording the simple-type-specifier rule to
better match the intent

"For the template-name to be part of the simple-type-specifier, the
name must be known to refer to a class-template."

Thanks

Johannes Schaub

unread,
Oct 15, 2017, 7:53:09 AM10/15/17
to std-dis...@isocpp.org
Perhaps even better, weaken the statement before it

"A type-specifier of the form typename opt nested-name-specifier
opt template-name is a placeholder for a deduced class type
([dcl.type.class.deduct]), provided that the template-name refers to a
class-template."

Richard Smith

unread,
Oct 15, 2017, 4:38:28 PM10/15/17
to std-dis...@isocpp.org
On 15 October 2017 at 04:53, 'Johannes Schaub' via ISO C++ Standard - Discussion <std-dis...@isocpp.org> wrote:
I think we want the syntactic rule to match any type template. It would probably make sense to invent an intermediate grammar term for this (type-template-name or template-type-specifier or similar). 

Johannes Schaub

unread,
Oct 16, 2017, 3:42:37 AM10/16/17
to std-dis...@isocpp.org
Am 15.10.2017 10:38 nachm. schrieb "Richard Smith" <ric...@metafoo.co.uk>:
On 15 October 2017 at 04:53, 'Johannes Schaub' via ISO C++ Standard - Discussion <std-dis...@isocpp.org> wrote:

--

It feels like that would be a non editorial change. While the little change I proposed appears to be editorial (admittedly with low priority).

Richard Smith

unread,
Oct 18, 2017, 6:54:48 PM10/18/17
to std-dis...@isocpp.org
Your change is also not editorial. You're assuming the "must be known to refer to a class template" part matches the intent, which I don't think it does; since the intent is not obvious, and this affects the normative meaning of the wording, we need CWG action to fix this. (And as much as anything else, we want this on the DR list so it is applied retroactively to the the de facto C++17 rules.)
Reply all
Reply to author
Forward
0 new messages