[Bug c++/94592] [10 Regression] ICE in non-type template parameter with constexpr constructor

2020-04-20 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94592

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #11 from Marek Polacek  ---
Fixed.

[Bug c++/94592] [10 Regression] ICE in non-type template parameter with constexpr constructor

2020-04-20 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94592

--- Comment #10 from CVS Commits  ---
The master branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:d419e176d74162af6513be0b3bc1031726543993

commit r10-7836-gd419e176d74162af6513be0b3bc1031726543993
Author: Marek Polacek 
Date:   Fri Apr 17 15:47:15 2020 -0400

c++: Fix ICE with { } as template argument [PR94592]

As an extension (there should be a CWG about this though), we support
braced-init-list as a template argument, but convert_nontype_argument
had trouble digesting them.  We ICEd because of the double coercion we
perform for template arguments: convert_nontype_argument called from
finish_template_type got a { }, and since a class type was involved and
we were in a template, convert_like created an IMPLICIT_CONV_EXPR.  Then
the second conversion of the same argument crashed in constexpr.c
because the IMPLICIT_CONV_EXPR had gotten wrapped in a TARGET_EXPR.
Another issue was that an IMPLICIT_CONV_EXPR leaked to constexpr.c when
building an aggregate init.

We should have instantiated the IMPLICIT_CONV_EXPR in the first call to
convert_nontype_argument, but we didn't, because the call to
is_nondependent_constant_expression returned false because it checks
!BRACE_ENCLOSED_INITIALIZER_P.  Then non_dep was false even though the
expression didn't contain anything dependent and we didn't instantiate
it in convert_nontype_argument.  To fix this, check
BRACE_ENCLOSED_INITIALIZER_P in cxx_eval_outermost_constant_expr rather
than in is_nondependent_*.

PR c++/94592
* constexpr.c (cxx_eval_outermost_constant_expr): Return when T is
a BRACE_ENCLOSED_INITIALIZER_P.
(is_nondependent_constant_expression): Don't check
BRACE_ENCLOSED_INITIALIZER_P.
(is_nondependent_static_init_expression): Likewise.

* g++.dg/cpp2a/nontype-class34.C: New test.
* g++.dg/cpp2a/nontype-class35.C: New test.

[Bug c++/94592] [10 Regression] ICE in non-type template parameter with constexpr constructor

2020-04-20 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94592

Richard Biener  changed:

   What|Removed |Added

  Known to work||9.3.0

--- Comment #9 from Richard Biener  ---
Indeed works with GCC 9.

[Bug c++/94592] [10 Regression] ICE in non-type template parameter with constexpr constructor

2020-04-17 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94592

Marek Polacek  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #8 from Marek Polacek  ---
Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2020-April/544068.html

[Bug c++/94592] [10 Regression] ICE in non-type template parameter with constexpr constructor

2020-04-15 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94592

--- Comment #7 from Marek Polacek  ---
Another problematical testcase:

struct A {
int i;
constexpr A(int n) : i(n) {}
};

template  struct B { int i; constexpr B() : i(a.i) { } };

template void bar () {
B<{1}> var;
}

void fu() {
bar();
}