Home > OS >  type_info compiler bug in MSVC?
type_info compiler bug in MSVC?

Time:07-28

So I've got this code:

#include <typeinfo>
#include <iostream>

void thing(char thing[2], int thing2) {

}

void thing2(char* thing, int thing2) {

}

template <typename T, typename U>
struct are_types_same {
    constexpr operator bool() const noexcept { return false; }
};

template <typename T>
struct are_types_same<T, T> {
    constexpr operator bool() const noexcept { return true; }
};

int main() {
    const std::type_info& info = typeid(thing);
    const std::type_info& info2 = typeid(thing2);

    std::cout << "typeid: " << (info == info2) << '\n';
    std::cout << "are_types_same: " << are_types_same<decltype(thing), decltype(thing2)>{} << '\n';
}

I was surprised to see that when comparing the type infos of the types in MSVC (x86, v19.32), the comparison yielded false, while the template specialization based comparison yielded true. I tried it on clang (x86-64, v14.0.0) and both yield true.

I've heard that MSVC is terrible at the newer C stuff like templates and such, is that what's happening here? Does this count as a compiler bug? Is it worth reporting somewhere?

CodePudding user response:

Does this count as a compiler bug?

Yes, this seems to be a msvc bug which has been reported as:

type_info yields incorrect result when comparing functions.

The two functions do have the same type and the check info == info2 should yield true.

  • Related