Skip to content

Instantly share code, notes, and snippets.

@hi2p-perim
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hi2p-perim/cb33048e8c0773e9bea8 to your computer and use it in GitHub Desktop.
Save hi2p-perim/cb33048e8c0773e9bea8 to your computer and use it in GitHub Desktop.
Tricky compilation error with __assume. Checked with VS2013 (/W4 /WX options enabled)
#include <iostream>
struct A
{
int n;
A(int n) : n(n) {}
};
A Func(int n)
{
if (n < 2)
{
return A(1);
}
else if (n >= 2)
{
return A(2);
}
else
{
#if 1
// OK
//__assume(0);
return A(3);
#elif 1
// OK
__assume(0);
//return A(3);
#else
// warning C4702, error C2220
__assume(0);
return A(3);
#endif
}
}
int main()
{
std::cout << Func(1).n << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment