[cfe-dev] CXXCtorInitializer different for templated and non templated code

Eli Friedman eli.friedman at gmail.com
Sun Aug 11 13:10:28 PDT 2013


On Sun, Aug 11, 2013 at 10:16 AM, Lukas Vogel
<lukedirtwalkerdev at gmail.com> wrote:
> Hi,
>
> I recently found out that for the following sample:
>
> class Pair {
>
>   int a,b;
>
> public:
>
>   Pair(int f,int s){
>
>     a=f;
>
>     b=s;
>
>   }
>
> };
>
>
> template <class T> class A : public Pair {
>
>   A(int f, int s) : Pair(f,s){}
>
> };
>
>
> Clang produces a ParenListExpr as init expression for the Pair(f,s) call.
>
>
> However if the class A has no template parameter i.e. just class A: public
> Pair{
>
> Clang produces a CXXConstructExpr as init expression .
>
>
> Why does it matter if there is a template argument for the
> CXXCtorInitializer ?
>

clang only builds a CXXConstructExpr when we know which constructor
will be called.  That isn't possible if the base in question is
dependent, or if we don't know which base will be initialized.  (In
this particular case, we can tell the exact type of the base which
will be initialized, but clang doesn't have code to reason about which
cases are safe.)

-Eli



More information about the cfe-dev mailing list