Running clang over the C++ standard header <vector>

I was curious how much trouble clang would have with <vector>
considering current template work, so I tried it out; ignoring using
declarations, I've managed to reduce the following issues, which I
think are distinct from each other.

Crash 1:
template<class T> struct a { typedef int v; };
template<class T, bool = a<T>::v> struct p { typedef double v; };

Crash 2:
template<class T> struct a {};
template<class T> T a<T>::x;

Crash 3:
template<typename T> T a() { return typename T::x(); }

Crash 4:
template<class T> class Q;
template<class T> class R : Q<Q<T> > {T current;};

Parser error on valid code:
struct a { template<class T> a(T) { T a; } };

I'm not sure whether it's appropriate to file bugs for all of these at
the moment...

-Eli

I was curious how much trouble clang would have with <vector>
considering current template work, so I tried it out; ignoring using
declarations, I've managed to reduce the following issues, which I
think are distinct from each other.

Thanks for doing this!

Crash 1:
template<class T> struct a { typedef int v; };
template<class T, bool = a<T>::v> struct p { typedef double v; };

Hrm, this should work. I'll look into it.

Crash 2:
template<class T> struct a {};
template<class T> T a<T>::x;

Known not to work; we haven't even started on out-of-line definitions of the members of templates.

Crash 3:
template<typename T> T a() { return typename T::x(); }

Known not to work; we haven't started work on function templates (

Crash 4:
template<class T> class Q;
template<class T> class R : Q<Q<T> > {T current;};

Also a bug; I'll look into it.

Parser error on valid code:
struct a { template<class T> a(T) { T a; } };

As with Crash 3, we don't have function-template support, so we know this won't work.

I'm not sure whether it's appropriate to file bugs for all of these at
the moment...

Feel free to file bugs for crashes 1 and 4, because support for those features is mostly available now and the examples should work.

  - Doug

Eli Friedman wrote:

I was curious how much trouble clang would have with <vector>
considering current template work, so I tried it out;

Which <vector> header is that? The one in MacOS X?

The results look encouraging.

Sebastian

I was curious how much trouble clang would have with <vector>
considering current template work, so I tried it out; ignoring using
declarations, I've managed to reduce the following issues, which I
think are distinct from each other.

Thanks for doing this!

You're welcome :slight_smile:

Crash 3:
template<typename T> T a() { return typename T::x(); }

Known not to work; we haven't started work on function templates (

The following also crashes:

template<class T> struct a { T b() { return typename T::x(); } };

Does this look like it should work?

I'm not sure whether it's appropriate to file bugs for all of these at
the moment...

Feel free to file bugs for crashes 1 and 4, because support for those
features is mostly available now and the examples should work.

Okay, will do.

-Eli

Eli Friedman wrote:

I was curious how much trouble clang would have with <vector>
considering current template work, so I tried it out;

Which <vector> header is that? The one in MacOS X?

No, this is Linux. Although, I think they both use the same C++ headers?

The results look encouraging.

Well, it's kind of hard to say... all the issues I listed are from the
first 1000 lines of the 5000 expanded lines of <vector>. That said,
it does look like we're successfully parsing substantial portions of
the template goop.

-Eli

Perhaps another interesting test case would be if we could run the boost
type_traits tests. IIUC, type traits should not require function templates,
and can be tested with static_assert so no need to generate code.

It would mean creating a Clang profile for Boost.Build though, or someone
who knows the current state of Boost cmake.

AlisdairM