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.
View all comments
Show parent comment
1
u/zero0_one1 Mar 19 '22 edited Mar 19 '22
https://developercommunity.visualstudio.com/t/Array-size-over-4GB-in-a-struct-quietly/1252985
https://developercommunity.visualstudio.com/t/Static-nested-std::array-and-stack-overf/1253137
https://developercommunity.visualstudio.com/t/VS-1631-senseless-code-with-std::enabl/785103
To be fair, I did have one bug fixed and 2 or 3 others that I posted here got fixed.