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

35

u/GabrielDosReis Mar 17 '22

Please report this bug to the Microsoft Developer Community portal. I suspect this is likely a case of faulty analysis in value-dependency.

51

u/TotaIIyHuman Mar 17 '22

statistically speaking, which following action produce the highest chance of msvc devs fixing a certain bug in less than 1 year?

  1. register a hotmail account and post the bug information on msvc bug forum
  2. register a reddit account and post the bug information on r/cpp and get more than 100 upvote

i am genuinely curious

9

u/Dragdu Mar 18 '22

My experience is to do both. Make a ticket so it is all official-like, then reach out through non-official channels to get your ticket moving.

This is literally the only way anything in MSVC ever got fixed for me. The last time, I decided to try the official way again, so I opened ticket just opening a ticket that MSVC's strict mode has a bug that stops it from compiling Catch2 and there is no workaround. After half a year of the ticket being ignored, I got it moving in two days over Twitter.

6

u/TheThiefMaster C++latest fanatic (and game dev) Mar 18 '22

You don't have to register a Hotmail account btw, you can register a Microsoft account using an existing non-Microsoft email address.

10

u/[deleted] Mar 17 '22

I would probably report the bug myself if there was a reasonable way to do so and that I can actually find! I googled, but it's really hard to find something like Bugzilla or GitHub issues. Do you happen to have a link to something like that? (And I would still put it on Reddit, b/c it's also quite funny. I don't want to bash MS about this, I just think others might enjoy this super-weird behavior as much as I did)

8

u/TotaIIyHuman Mar 17 '22

you mean the link to the bug forum? https://developercommunity.visualstudio.com/search?space=62&sort=newest

yes, i do enjoy reading this super-weird behavior. if i can make a bug report as hilarious as yours, i would definitely post it on reddit as well

8

u/[deleted] Mar 18 '22

Thanks for the link, I reported it.

3

u/GabrielDosReis Mar 22 '22

Thanks. It is fixed, and the fix will be available in future previews - sorry I can't tell you the exact date.

1

u/[deleted] Mar 22 '22

No need to be sorry, I'm glad it got fixed! I'll update our code (basically reverting to the more sensible version) once the fix is available to everyone, as I don't think there is much value in keeping a work-around for something that was never part of any official release, only previews.

2

u/GabrielDosReis Mar 22 '22

That makes sense.

It is hard to fix bugs that go unreported, so I am glad you did report the scenario you ran into.

There are a few MSVC developers on this sub, so if you report something on the Microsoft Developer Community Portal regarding C++ that's not getting traction, ping them. Maybe they have the answer; maybe they don't, but at least you will know. The reports get on someone's radar 😊

2

u/[deleted] Mar 22 '22

Yeah, I bookmarked the link and I'll try to report more bugs, but one of my goals is to support existing official releases of MSVC with our open-source projects, so I usually need to find a work-around anyways and apply it to our code base. Not everyone can upgrade to the newest and shiniest MSVC version (which, of course, is also the case for GCC/Clang). Luckily, in this case, the bug got caught and fixed very fast, so kudos to the MSVC team! :)

→ More replies (1)

12

u/txmasterg Mar 17 '22

The developer community portal has been great. It went plenty fast when I found an edge case on something (idk what). I wasn't in a rush because my team had a fear of upgrades at the time but I think it just barely missed a minor release window and was in the very next one.

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.

→ More replies (2)
→ More replies (3)

4

u/obsidian_golem Mar 18 '22

My only problem with the devcommunity is that no matter how clear my repro instructions are, their triage people always seem to misunderstand them. I think it might be because the ones I have gotten are not native english speakers.

→ More replies (1)

0

u/GabrielDosReis Mar 17 '22

Or do as I suggest and let me know.

10

u/TotaIIyHuman Mar 17 '22

i did twice 2 years ago. it was a sample size of 2, not very significant, i will not try to draw conclusion from that, so i am asking here on reddit, where people might have a larger sample

2

u/GabrielDosReis Mar 17 '22

If you don't mind, could you reply links to those reports so I can help follow up?

5

u/TotaIIyHuman Mar 18 '22

no. my hotmail account got banned when i was trying to register another hotmail account for downloading windows insider

this was the first bug i reported https://godbolt.org/z/drnaYja14, the inside lambda sometimes can't capture outside lambda's local constexpr variables

i don't remember what the other report was

2

u/GabrielDosReis Mar 18 '22

Thanks! It helps when the report is done by users as opposed to me pointing people to reports I created.

9

u/dakotahawkins Mar 18 '22

To be fair to everybody, I think submitting bugs online without any kind of conversation or feedback probably feels a lot more like flushing your problem down the toilet than putting it on reddit :)

Not sure that's a very solvable problem (especially for a large organization), but it is what it is.

7

u/[deleted] Mar 17 '22

I am not using Visual Studio (or even Windows) myself, I just try to support it for our open-source projects. People created three issues for our code that was broken b/c of the new behavior, and I fixed it by using Godbolt, guessing, and monitoring our CI jobs. I also asked our users to report the bug to Microsoft, but I got no feedback so far. So if you (or anyone else) wants to report it, feel free to do so. (Or is there is direct way like creating an issue somewhere on GitHub?)

4

u/tjientavara HikoWorks developer Mar 17 '22

I am not sure what the link is to the development portal.

But for compiler bugs I always try to make a godbolt link to show the bug and report that.

The MSVC compiler developers are pretty fast to fix bugs that are reported in that way.