Community
Participate
Working Groups
template <int> struct foo {}; template <> struct foo<1> { typedef int type; }; template <typename T> struct A { typedef typename foo<sizeof(T)>::type type; // ERROR HERE }; The error at the indicated line is: "Type 'foo<sizeof(T)>::type' could not be resolved" There exist instantiations of A for which the line is valid (namely, those with sizeof(T) == 1), so it is incorrect to mark the line as an error.
The example contains a dependent expression.
Hmm... it seems a lot of things use dependent expressions. The example above shows up in the following metaprogramming trick: template <typename T> struct some_trait { typedef char one; typedef struct { char x[2]; } two; one check(...); two check(some-arguments); static const bool value = sizeof(expr) == 1; }; where 'expr' is some expression involving T, and 'expr' and the arguments to the second overload of check are devised to that the second overload is chosen for some types T, and the first for others. This is used to implement type traits metafunctions like is_convertible<A, B>, which are used all over the place in Boost. Is it difficult to add support for dependent expressions? Maybe just sizeof() at first, since it was already there in C++03, while decltype() is new to C++11?
(In reply to comment #2) > ... > Is it difficult to add support for dependent expressions? Maybe just sizeof() > at first, since it was already there in C++03, while decltype() is new to > C++11? It is not difficult in terms of complexity, however it is a rather large change. The change is large because a bunch of algorithms, including function overload resolution and calculation of expression-types, assume that they can pick up information directly from the AST (rather than being able to work on something that was specialized/instantiated). Unfortunatly I am always short on time, however bug 299911 is one of the things I want to get done.
(In reply to comment #3) > (In reply to comment #2) > > ... > > Is it difficult to add support for dependent expressions? Maybe just sizeof() > > at first, since it was already there in C++03, while decltype() is new to > > C++11? > It is not difficult in terms of complexity, however it is a rather large > change. The change is large because a bunch of algorithms, including function > overload resolution and calculation of expression-types, assume that they can > pick up information directly from the AST (rather than being able to work on > something that was specialized/instantiated). > > Unfortunatly I am always short on time, however bug 299911 is one of the things > I want to get done. Any update on the support for dependent expressions? Does it have a chance of making the Juno release?
At the moment I have very little time to spend on CDT, I will not be able to look at this for Juno.
Fixed together with bug 299911.