Created on 2022-06-18.00:00:00 last changed 3 months ago
Subclause 13.8.3.2 [temp.dep.type] paragraph 7 has a list of types considered to be dependent. This list covers placeholder types only insofar as it has an entry about decltype(expression). Subclause 13.8.3.3 [temp.dep.expr] paragraph 3 has a list of expression forms not considered dependent unless specific types named by the expressions are dependent. This list includes forms where placeholder types are allowed. For example, the wording does not say that the new-expression at #1 (below) is dependent, but it ought to be:
template <typename T> struct A { A(bool, T); };
void g(...);
template <typename T>
auto f(T t) { return g(new A(t, 0)); } // #1
int g(A<int> *);
int h() { return f<void *>(nullptr); }
Some implementation even treats an obviously non-dependent case as dependent:
template <typename T, typename U> struct A { A(T, U); }; void g(...); // #1 template <typename T> auto f() { return g(new A(0, 0)); } // #1 or #2? int g(A<int, int> *); // #2 void h() { return f<void *>(); }
A similar example that is non-dependent:
template <typename T, typename U = T> struct A { A(T, U); }; void g(...); template <typename T> auto f() { return g(new A(0, 0)); } int g(A<int> *); void h() { return f<void *>(); }
And another non-dependent one:
template <typename T, typename U = T> struct A { A(T); }; void g(...); template <typename T> auto f() { return g(new A(0)); } int g(A<int> *); void h() { return f<void *>(); }
And here is an example that is dependent:
template<class T>
struct S {
template<class U = T> struct A { A(int); };
auto f() { return new A(0); } // dependent return type
};
Possible resolution:
Change in 7.6.2.8 [expr.new] paragraph 2 as follows:
If a placeholder type (9.2.9.6 [dcl.spec.auto]) or a placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) appears in the type-specifier-seq of a new-type-id or type-id of a new-expression, the allocated type is deduced as follows: Let init be the new-initializer , if any, and T be the new-type-id or type-id of the new-expression, then the allocated type is the type deduced for the variable x in the invented declaration (9.2.9.6 [dcl.spec.auto]):T x init ;
Insert new paragraphs before 13.8.3.2 [temp.dep.type] paragraph 7 and change the latter as follows:
An initializer is dependent if any constituent expression (6.9.1 [intro.execution]) of the initializer is type-dependent. A placeholder type (9.2.9.6.1 [dcl.spec.auto.general]) is dependent if it designates a type deduced from a dependent initializer.
A placeholder for a deduced class type (9.2.9.7 [dcl.type.class.deduct]) is dependent if
- it has a dependent initializer or
- any default template-argument of the primary class template named by the placeholder is dependent when considered in the scope enclosing the primary class template.
A type is dependent if it is
- ...
- a function type whose exception specification is value-dependent,
- denoted by a dependent placeholder type,
- denoted by a dependent placeholder for a deduced class type,
- ...
Change in 13.8.3.3 [temp.dep.expr] paragraph 3 as follows:
... Expressions of the following forms are type-dependent only if the type specified by the type-id, simple-type-specifier or new-type-id is dependent, even if any subexpression is type-dependent:
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-06-18 00:00:00 | admin | create |