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

Constraint not considered a constant expression in inherited constructor #35

Open
JohelEGP opened this issue Nov 11, 2019 · 3 comments
Open

Comments

@JohelEGP
Copy link

I'm not sure whether this is intended or not, so I'm just putting it out here.
https://godbolt.org/z/Xbx832

template <bool B>
struct X_base
{
    X_base(int) requires B { }
};

struct X : X_base<true>
{
    using X_base::X_base;
};

void f()
{
    X x{42};
}
<source>:4:26: error: substitution into constraint expression resulted in a non-constant expression

    X_base(int) requires B { }

                         ^

<source>:4:26: note: subexpression not valid in a constant expression

1 error generated.

Compiler returned: 1
@JohelEGP
Copy link
Author

I just noticed it works with GCC: https://godbolt.org/z/paKtpP.

@JohelEGP
Copy link
Author

Manually writing out the inherited constructor works, so maybe GCC is right. https://godbolt.org/z/2WASak.

X(int) : X_base{42} { }

@JohelEGP
Copy link
Author

Also happens with dependent names: https://godbolt.org/z/yBdurY.

struct X_base
{
    template <class T>
    X_base(T) requires requires { T{42}; } { }
};

struct X : X_base
{
    using X_base::X_base;
};

void f()
{
    X x{42};
}

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

1 participant