[cfe-dev] A question about C++ mangling for a complicated template case

Jiangning Liu liujiangning1 at gmail.com
Wed Oct 22 03:58:40 PDT 2014


Hi,

I have a question about C++ name mangling.

For the following small program (I failed to get it further minimized),
clang++ and g++ generate different symbols for function fin introduced by
the last specialization statement.

clang++: AA<3>::aa BB::fin<3, AA>(AA const&)
g++:        AA<3>::aa BB::fin<3, AA>(AA<3> const&)

If I change the return type of fin to be void, I can see the argument AA<3>
can be correctly generated for clang++.

{code}
template <int dim>

class AA
{
    template <class DH> struct Iter;

    template <template <int> class DH>
    struct Iter<DH<3> >
    {
        typedef DH<3> AA_type;
    };

    typedef Iter<AA<dim> > IteratorSelector;
public:
    typedef typename IteratorSelector::AA_type aa;
};

class BB
{
    template <int dim, template<int> class C>
    static typename C<dim>::aa fin (const C<dim> &container);

    template <int dim>
    static void pp (const AA<dim>& dof)
    {
        typename AA<dim>::aa temp = fin (dof);
    }
};

template void BB::pp<3> (const AA<3>&);
{code}

So anybody know why?

This problem will cause failure of linking object files generated by
clang++ and g++ separately, and potentially introduce run-time bugs.

Thanks,
-Jiangning
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141022/c0a1929e/attachment.html>


More information about the cfe-dev mailing list