[cfe-dev] Adding template default parameter with as typed explicit parameter
eli.friedman at gmail.com
Wed Sep 26 12:57:32 PDT 2012
On Wed, Sep 26, 2012 at 6:10 AM, Philippe Canal <pcanal at fnal.gov> wrote:
> With the class template:
> template <typename T> class Coord;
> template <typename T, typename U = Coord<T> > class Point;
> If the user code contains:
> typedef long size_t;
> Point<size_t> p;
> when traversing the AST, reaching 'p', I have access to a clang::Type
> named 'Point<size_t>' which directs the CXXRecordDecl named
> 'Point<long, Coord<long> >.
The CXXRecordDecl has to use the canonical types so we don't try to
instantiate Point twice if the user writes e.g. "Point<size_t> x;
Point<unsigned long> y;". I suppose it could store non-canonical
arguments corresponding to the first instantiation as well... but we
haven't had any use for that in the past.
> Is there a way to create (from Point<size_t>) a type which would be
> named 'Point<size_t, Coord<size_t> >'. I.e. which preserves the
> typedef when expanding/adding the template default parameters?
AFAIK no... I'm pretty sure Sema never computes it, and you can't
compute it yourself without the code to perform template type
substitution which isn't exposed outside Sema.
More information about the cfe-dev