constexpr memeber function not constexpt anymore in v10

Jonathan Wakely jwakely.gcc@gmail.com
Wed Feb 19 10:11:00 GMT 2020


On Wed, 19 Feb 2020 at 07:53, Klaus Doldinger
<klaus.doldinger64@gmail.com> wrote:
>
> The following was possible in v9:
>
> template<auto N>
> struct A {
>     constexpr auto size() const {
>         return N;
>     }
> };
>
> template<typename A>
> void foo(const A& a) {
>     constexpr auto s = a.size();
> }
>
> int main() {
>     A<10> x1;
>     foo(x1);
> }
>
> In v10 this is rejected.
>
> Looks like a bug?

No, I don't think so. The parameter a is not a constant expression, so
a.size() is not a constant expression, so can't be used to initialize
a constexpr variable.



More information about the Gcc-help mailing list