clang (c++) 在专业化中找不到名称

clang (c++) can't find name within specialization

以下代码使用 gcc (g++) 编译,但使用 clang (c++) 编译。

我原以为行 n1::generic(*it); 会查找 my_traits<bool>(或 my_traits<const bool>)专业化,但它似乎在查找名称 specific vector(常量?)来自同一专业。

另外,这是 bool 特有的。其他类型如 int 工作正常。 (我尝试添加 my_traits<vector<bool> >(以及 const bool)专业化,但没有帮助)。

#include <vector>

namespace n1 {

    template <class T> struct my_traits { };

    template <> struct my_traits<bool> {
        static void specific(bool b) { }
    };

    template <> struct my_traits<int> {
        static void specific(int b) { }
    };

    template <typename T> void generic(const T& t)
    {
        my_traits<T>::specific(t);
    }

    template <typename T> struct my_traits<std::vector<T> > {
        static void specific(const std::vector<T>& b)
        {
            if (! b.empty()) {
                for (typename std::vector<T>::const_iterator it = b.begin();
                        it != b.end(); ++it) {
                    n1::generic(*it);
                }
            }
        }
    };
}

namespace n2 {
    struct ArrayOfBoolean {
        std::vector<bool> values;
    };

    struct ArrayOfInt {
        std::vector<int> values;
    };
}

namespace n1 {

    template<> struct my_traits<n2::ArrayOfBoolean> {
        static void specific(const n2::ArrayOfBoolean& v) {
            n1::generic(v.values);
        }
    };

    template<> struct my_traits<n2::ArrayOfInt> {
        static void specific(const n2::ArrayOfInt& v) {
            n1::generic(v.values);
        }
    };
}

c++     codec.cc   -o codec
In file included from codec.cc:1:./codec.h:17:23: error: no member named 'specific' in 'n1::my_traits<std::__1::__bit_const_reference<std::__1::vector<bool,std::__1::allocator<bool> > > >'
    my_traits<T>::specific(t);
    ~~~~~~~~~~~~~~^
./codec.h:26:25: note: in instantiation of function template specialization 'n1::generic<std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
    n1::generic(*it);
        ^
./codec.h:17:23: note: in instantiation of member function 'n1::my_traits<std::__1::vector<bool, std::__1::allocator<bool> > >::specific' requested here
    my_traits<T>::specific(t);
                  ^
./codec.h:47:17: note: in instantiation of function template specialization 'n1::generic<std::__1::vector<bool, std::__1::allocator<bool> > >' requested here
    n1::generic(v.values);
        ^
1 error generated.

看起来很奇怪,vector<bool> 不包含任何 bool。只有你无法真正引用的位。

所以在 n1::generic(*it); 中没有 const bool&,只有 __bit_const_reference 代理 class。