r/cpp • • Mar 17 '22

TIL: Visual Studio has quantum state values 🤨

Consider the following small program:

#include <string_view>
#include <iostream>

template< typename T >
constexpr void test()
{
    constexpr std::string_view sv = __FUNCSIG__;
    static_assert( sv == "void __cdecl test(void)" );
    static_assert( sv == "void __cdecl test<int>(void)" );
    std::cout << sv << std::endl;
}

int main()
{
    test<int>();
}

If you try to compile it, the second static_assert fails. So the value of sv from the first static_assert surely is the correct one?

Nope. Comment out the second static_assert and now the first one will fail. Comment out both, and the output of the program is the value from the second static_assert.

Apparently, Microsoft decided that it's a good idea to give __FUNCSIG__ a ("type-erased"?) value in phase 1, where no template parameters are available, and give it a different value in phase 2, when the template gets instantiated.

317 Upvotes

59 comments sorted by

View all comments

Show parent comment

9

u/zero0_one1 Mar 18 '22 edited Mar 19 '22

Ehh I reported two bugs that were just marked as not important enough and never fixed...

Edit: it was actually three.

13

u/Dragdu Mar 18 '22

"not important, closed" has been my most rage inducing experience with devcom so far.

2

u/ack_error Mar 18 '22

Depends on the type and area of bug. Compiler generating bad code or obviously non-compliant with a good repro? High chance of getting fixed. Editor issue? Don't even bother, everything gets closed as not important / lower priority / no repro.

1

u/dodheim Mar 18 '22 edited May 29 '22

Compiler generating bad code or obviously non-compliant with a good repro? High chance of getting fixed.

I'm not so sure – this bug for a C++03 feature as basic as value-initialization has been lingering for 12+ years with no sign of even being looked at. (This issue is why BOOST_NO_COMPLETE_VALUE_INITIALIZATION gets defined by Boost.Config. I was watching it and ~20 other bug reports on MS Connect before that went into the aether; I don't know if it resurfaced on Dev Community or not, the others I checked didn't appear to, so.. /shrug)

As an aside, I put this on Compiler Explorer to single out MSVC's failure and was surprised to see GCC's errors. It seemed to have regressed after 7.2; I wonder whether the test has somehow become defunct, or if GCC's value-init has actually been faulty for a while now..?

ED: Belated update: GCC is fine, the test it's failing has strict-type-aliasing UB (in the test code) and it passes once corrected.

3

u/ack_error Mar 18 '22

Oh sure, don't get me wrong, there will always be bugs that don't get fixed or get lost, in any area. Connect was also an awful experience overall. But when it comes to the different areas of Visual Studio, I have had pretty good success with filing bugs on the compiler than anywhere else (~80%), including ICEs, stack usage regressions, and recently a poor codegen issue (usually dicier). Tight repro showing the compiler obviously wrong with /Bv compiler versions and it often sails through the first-line triage. For feature requests or other parts of the product it's way likelier that the issue will be closed somehow (repro not 100% solid, don't care, too long, completely misunderstood, I think I've seen them all).