[cfe-dev] Flag for better diagnosing errors in member templates

Jordan Rose jordan_rose at apple.com
Sat Jun 30 11:36:42 PDT 2012

On Jun 30, 2012, at 8:39 AM, Johannes Schaub wrote:

> I would appreciate a clang flag that leads to better diagnosis in member 
> templates. Consider
>     template<typename T>
>     struct A {
>       template<typename U>
>       void f(U u) {
>         T t;
>         // ...
>       }
>     };
>     struct B;
>     template struct A<B>;
> A<B>::f's definition is ill-formed without a diagnostic being required 
> and Clang does not diagnose it. But Clang aims for catching as many bugs 
> as possible in user programs, and finding this bug appears to be 
> possible with the current clang abilities.
> What do you think?

I'm pretty sure this is NOT an issue until A<B>::f is instantiated. It's possible a specialization of A<B>::f could be introduced that did not declare a B, or that B's definition could be completed before A<B>::f is actually used. That said, I understand your point about "catching as many bugs as possible", so maybe we could add this as an optional warning?

I'm basing this on my intuition of how C++ behaves, though, not on the actual standard.


More information about the cfe-dev mailing list