[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-03-05 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

Marek Polacek  changed:

   What|Removed |Added

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

--- Comment #9 from Marek Polacek  ---
Unfortunately backporting is proving to be difficult.  nontype-class28.C ICEs
without r273597.  That was backported to 9 in r273597, but the
build_converted_constant_expr_internal bit is different.  Tweaking GCC 9 so
that it doesn't copy a class in a template breaks everything.

I'm too nervous about messing with that now.  So closing.

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-29 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

--- Comment #8 from Marek Polacek  ---
Fixed on trunk so far, will backport to 9 sometime soon.

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-29 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

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

https://gcc.gnu.org/g:423284053ec51832bc4c823fb90dc41e632e37ac

commit r10-6329-g423284053ec51832bc4c823fb90dc41e632e37ac
Author: Marek Polacek 
Date:   Tue Jan 28 17:44:21 2020 -0500

c++: Fix class NTTP with template arguments [PR92948]

This PR points out an ICE with an alias template and class NTTP, but I
found that there are more issues.  Trouble arise when we use a
(non-type) template parameter as an argument to the template arg list of
a template that accepts a class NTTP and a conversion to a class is
involved, e.g.

  struct A { A(int) { } };
  template struct B { };

  template void fn () {
  B b;
  }

Normally for such a conversion we create a TARGET_EXPR with an
AGGR_INIT_EXPR that calls a __ct_comp with some arguments, but not in
this case: when converting X to type A in convert_nontype_argument we
are in a template and the template parameter 'X' is value-dependent, and
AGGR_INIT_EXPR don't work in templates.  So it just creates a TARGET_EXPR
that contains "A::A(*this, X)", but with that overload resolution fails:
  error: no matching function for call to 'A::A(A*, int)'
That happens because finish_call_expr for a BASELINK creates a dummy
object, so we have 'this' twice.  I thought for the value-dependent case
we could use IMPLICIT_CONV_EXPR, as in the patch below.  Note that I
only do this when we convert to a different type than the type of the
expr.  The point is to avoid the call to a converting ctor.

The second issue was an ICE in tsubst_copy: when there's a conversion
like the above involved then
 /* Wrapper to make a C++20 template parameter object const.  */
  op = tsubst_copy (op, args, complain, in_decl);
might not produce a _ZT... VAR_DECL with const type, so the assert
  gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (op)));
fails.  Allowing IMPLICIT_CONV_EXPR there probably makes sense.

And since convert_nontype_argument uses value_dependent_expression_p
a lot, I used a dedicated bool to speed things up.

2020-01-29  Marek Polacek  

PR c++/92948 - Fix class NTTP with template arguments.
* pt.c (convert_nontype_argument): Use IMPLICIT_CONV_EXPR when
converting a value-dependent expression to a class type.
(tsubst_copy) : Allow IMPLICIT_CONV_EXPR
as the result of the tsubst_copy call.

* g++.dg/cpp2a/nontype-class28.C: New test.
* g++.dg/cpp2a/nontype-class29.C: New test.

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-28 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

Marek Polacek  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code, patch,
   ||rejects-valid

--- Comment #6 from Marek Polacek  ---
Now posted https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01896.html

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-28 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

--- Comment #5 from Marek Polacek  ---
I have a patch that fixes these two issues (it uses IMPLICIT_CONV_EXPR).

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

--- Comment #4 from Marek Polacek  ---
A related test that I think should compile:

struct A {
  constexpr A(int) { }
};

template
struct B {
};

template
void foo()
{
  B b; // works with B<1>
}

void
fn ()
{
  foo<1>();
}

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

--- Comment #3 from Marek Polacek  ---
Test I've been playing with:

struct A {
  constexpr A(int) { }
};

template
struct B {
  using U = unsigned;
};

template
using U = B;

//template::U> // ok
template::U>  // ICE
//template::U> // error
void foo()
{
}

void
g ()
{
  foo<1>();
}

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2020-01-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

--- Comment #2 from Marek Polacek  ---
Because of the alias template build_converted_constant_expr produces a
TARGET_EXPR containing a TEMPLATE_PARM_INDEX which makes it value-dependent. 
So we don't call get_template_parm_object here

 7449   /* Replace the argument with a reference to the corresponding
template
 7450  parameter object.  */
 7451   if (!value_dependent_expression_p (expr))
 7452 expr = get_template_parm_object (expr, complain);

we crash in pt.c:
16396   /* Wrapper to make a C++20 template parameter object const.
 */
16397   op = tsubst_copy (op, args, complain, in_decl);
...
16405   gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (op)));

because tsubst_copy didn't turn op into one of those _ZT... VAR_DECLs.

Poking more.

[Bug c++/92948] internal compiler error: in tsubst_copy, at cp/pt.c:15788

2019-12-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92948

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-12-16
 CC||mpolacek at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek  ---
This tsubst_copy ICE started with r267108 but before that we had another ICE:

92948.C:13:21: internal compiler error: in cxx_eval_constant_expression, at
cp/constexpr.c:4594
   13 | using Bbb = Bbb_;
  | ^
0x8982d3 cxx_eval_constant_expression
../../gcc/cp/constexpr.c:4594
0x88b4a5 cxx_eval_call_expression
../../gcc/cp/constexpr.c:1508
0x8970c9 cxx_eval_constant_expression
../../gcc/cp/constexpr.c:4288
0x899db8 cxx_eval_outermost_constant_expr
../../gcc/cp/constexpr.c:5023
0x89a62d cxx_constant_value(tree_node*, tree_node*)
../../gcc/cp/constexpr.c:5144
0xa5be7a get_template_parm_object
../../gcc/cp/pt.c:6726
0xa5dab7 convert_nontype_argument
../../gcc/cp/pt.c:7187
0xa60ec2 convert_template_argument
../../gcc/cp/pt.c:8094
0xa62aa2 coerce_template_parms
../../gcc/cp/pt.c:8574
0xa631ac coerce_innermost_template_parms
../../gcc/cp/pt.c:8695
0xa65769 lookup_template_class_1
../../gcc/cp/pt.c:9392
0xa67db7 lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
../../gcc/cp/pt.c:9751
0xae8a49 finish_template_type(tree_node*, tree_node*, int)
../../gcc/cp/semantics.c:3257
0x9fabe3 cp_parser_template_id
../../gcc/cp/parser.c:16103
0xa0773f cp_parser_class_name
../../gcc/cp/parser.c:22660
0x9e74f8 cp_parser_qualifying_entity
../../gcc/cp/parser.c:6638
0x9e6598 cp_parser_nested_name_specifier_opt
../../gcc/cp/parser.c:6324
0x9fd271 cp_parser_simple_type_specifier
../../gcc/cp/parser.c:17442
0x9fc7bb cp_parser_type_specifier
../../gcc/cp/parser.c:17115
0xa05143 cp_parser_type_specifier_seq
../../gcc/cp/parser.c:21404

the second ICE started with Implement P0732R2, class types in non-type template
parameters. / r265789, before that the test was rejected.

So confirmed, though it may be a dup too.