[cfe-commits] [PATCH]Fix a false warning against explicit template specialization for nested types

Michael Han Michael.Han at autodesk.com
Wed Jun 1 05:15:17 PDT 2011


Hi there, I find a clang warning is suspicious.

Consider this code:

template <typename T1> struct A {
    template <typename T2> struct B {
        template <typename T3> struct C {
            static void foo();
        };
    };
};

template <> struct A<int> {
    template <typename T2> struct B {
        template <typename T3> struct C {
            static void foo();
        };
    };
};

template <> template <typename T3> struct A<int>::B<int>::C {
    static void foo();
};

Clang would emit a warning like "extraneous template parameter list in template specialization" at
template <> template <typename T3> struct A<int>::B<int>::C. I think the code should not trigger a warning here since the first template <> is applied to the explicit specialization of the nested class template B, not to A as indicated by the "note" of clang diagnostic (since A has already had a declaration of an explicit specialization so the template <> for A could be omitted)

After looking at the code, it looks like the problem is in SemaTemplate.cpp when iterating the nested types, the loop is terminated before it should be so the template header is never consumed. The attached patch fixes this, with a test added.

Please review, thanks!

Cheers
~Michael

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110601/cb81d795/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exp.spec.patch
Type: application/octet-stream
Size: 1652 bytes
Desc: exp.spec.patch
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110601/cb81d795/attachment.obj>


More information about the cfe-commits mailing list