MSVC 2022 compiler bug

Static asserts in the code below do not fail with MSVC 19.32.31332 for x86:

#include <string>

int main()
    std::string v = "abc";

    auto func = [v]()
        auto& l_ref = v;

        static_assert(std::is_same_v<decltype(l_ref), std::string&>);

        auto&& r_ref = std::move(v);

        static_assert(std::is_same_v<decltype(r_ref), std::string&&>);


    return 0;

that is MSVC compiler bug. With GCC both l_ref and r_ref are const references.

Thanks to

Reported this to Microsoft.

MSVC syntax highlighter (with double Ctrl) displays the references as const:

Leave a Reply

Your email address will not be published. Required fields are marked *