Skip to content

Instantly share code, notes, and snippets.

@marzer
Last active April 21, 2021 12:53
Show Gist options
  • Save marzer/1899311fc27a9a1c769d6ba325741982 to your computer and use it in GitHub Desktop.
Save marzer/1899311fc27a9a1c769d6ba325741982 to your computer and use it in GitHub Desktop.
MSVC 16.10.0 Preview 2 consteval bug repro
// Minimal repro for producing an erroneous C7595 error in Visual Studio 2019 16.10.0 Preview 2 (CL 19.29.30031.0).
//
// Steps to reproduce:
// 1. Compile with /std:c++latest in Visual Studio 2019 16.10.0 Preview 2 (CL 19.29.30031.0)
// 2. Observe C7595 at the line marked below
// 3. Comment out the 'REPRO' line and rebuild
// 4. Observe that plain ol' constexpr works OK
using size_t = decltype(sizeof(void*));
#define REPRO // comment this out to see a workaround using constexpr
#ifdef REPRO
#define CONSTEVAL consteval
#else
#define CONSTEVAL constexpr
#endif
[[nodiscard]]
CONSTEVAL size_t operator"" _sz(unsigned long long n) noexcept
{
return static_cast<size_t>(n);
}
int get_val(size_t coeff = 0_sz) noexcept // C7595
{
return static_cast<int>(coeff);
}
int main()
{
return get_val();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment