Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC /permissive- leads to "expression did not evaluate to a constant" #102

Closed
sdebionne opened this issue May 26, 2021 · 3 comments
Closed

Comments

@sdebionne
Copy link

In some circumstance -I have a hard time reducing the repro, compiling with MSVC 2019 and /std=c++17 /permissive-, I get error C2131.

Here is the repro I have so far:

#include <string>

/// Returns the length of a C style array (that has not decayed into a pointer)
template <typename T, std::size_t sz>
inline constexpr std::size_t lengthof(T (&)[sz])
{
    return sz;
}

#include "https://raw.githubusercontent.com/aantron/better-enums/0.11.3/enum.h"

namespace foo {

BETTER_ENUM(bar, int,
           one,
           two
);

} //namespace foo

and the result:

<source>(15): error C2131: expression did not evaluate to a constant
<source>(15): note: failure was caused by call of undefined function or one not declared 'constexpr'
<source>(15): note: see usage of 'foo::bar::bar'

Easily reproducible on godbolt.

This really looks like a compiler bug (the enum constructor not being seen as constexpr), but given the difficulty to reduce the repro, I cannot tell what it is and if there is workaround...

@sdebionne
Copy link
Author

I have finally managed to reduce the issue -without better enum.

#include <cstddef>

/// Returns the length of a C style array (that has not decayed into a pointer)
template <typename T, std::size_t sz>
inline constexpr std::size_t lengthof(T (&)[sz])
{
    return sz;
}

struct foo
{
    struct bar {};
    constexpr explicit foo(bar) {}
};
inline constexpr foo foo{foo::bar{}};

@sdebionne
Copy link
Author

Reported to MS Community

@aantron
Copy link
Owner

aantron commented May 26, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants