New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[temp.arg.explicit] p5 Explicitly specified template arguments can enforce to use the template #5341
Comments
@opensdh, I thought |
@jensmaurer That is [temp.arg.general] p8
|
Great. So, what is the remaining issue, exactly? |
No hazy anymore. |
@jensmaurer The first change may be an improvement
using type = X<int>; // is not valid template-id |
You can't form a template-id if you don't have a template-name to start with (unless it's a |
The non-simple-template-id possibilities can name only function template specializations (but operator overloads, not conversion functions, @jensmaurer), so the latter part of the suggested change does nothing. |
@jensmaurer @opensdh Whether a name is interpreted as a
There is no rule that specifies that a template<class T>
class X{}; which is grammatically equivalent to template-head declaration where the declaration is a class-specifier whose class-name is an identifier that is not a Consider this example: struct C{
struct X{};
};
template<class T>
T::X<int> fun(){/*...*/ };
fun<C>(); According to [temp.names] p3 and [temp.res.general] p4, the symbol
Thus, |
The temp.names p3 rules help to determine at parse time whether some < is an operator or the start of a template-argument-list. The interpretation whether something is a template-name or not is locked in at parse time (with the help of the < disambiguation rules), not determined at instantiation time. The "is valid" checks need to be performed at instantiation time, though, which is too late. |
So, for Even, we can simplify the example to: struct C{
struct X{};
};
C::X<int> fun(); [temp.names]/3.4 still interpret the symbol
The reason will be obvious. |
We say that a class-name is introduced by a class declaration, and lookup essentially returns a class-name when it finds a name declared as a class. We have something similar for _template-name_in temp.param p3 (a template template parameter introduces a template-name); we seem to be lacking wording that a template declaration introduces its declarator-id as a template-name. Once we have that, the < would cause a template-name to be required at the point of use, but the lookup result doesn't fit, and it's ill-formed. Similar to |
It seems it is exact #5345. We have a violent agreement. |
It seems that this is not explicitly espoused with a formal rule. lookup only concerns name and declarations, where name is defined as:
That is, we still lack the wording that once an identifier(name) is determined to be an entity, the identifier will be promoted to the corresponding component(e.g. class-name, namespace-name, or declarator-id) of that declaration. The grammar together with rules is used to restrict language constructs. |
[temp.arg.explicit] p5 just states:
However, we lack the rule to interpret the reason. First,
f<>
is syntactically ok as per grammar. [basic.lookup] has no special treatment to the namef
when have determined that the<
is interpreted as the delimiter of a template-argument-list according to [temp.names] p3: discards the name that denotes a non-template function.The only relevant reason may be [temp.deduct.general] p2:
However, [temp.names] p7 is not friendly to interpret whether a template-id is valid when its component name does not denote a template.
[temp.names] p7 should first admit that a
template-id
is not valid if its component name does not denote a template, it would be a simple/direct way to interpret the aforementioned case. I think it is also reasonable as the initial condition. [temp.names] p7 may be changed to:After applying this modification,
f<>
is not valid if the namef
denotes#2
, which results in type deduction fails as per [temp.deduct.general] p2. In the current draft, [temp.over] is drafted in terms of the function templates,[temp.over] should also admit that
#2
won't be added to the candidate set if it is referenced by an invalidtemplate-id
(f<>
results in deduction fails). This will interpret why an empty template argument list can be used to enforce to use of the template.The text was updated successfully, but these errors were encountered: