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<A a> struct B { }; template<int X> void fn () { B<X> 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 <polacek@redhat.com> 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) <case VIEW_CONVERT_EXPR>: 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.
Name |
Last commit
|
Last update |
---|---|---|
INSTALL | Loading commit data... | |
config | Loading commit data... | |
contrib | Loading commit data... | |
fixincludes | Loading commit data... | |
gcc | Loading commit data... | |
gnattools | Loading commit data... | |
gotools | Loading commit data... | |
include | Loading commit data... | |
intl | Loading commit data... | |
libada | Loading commit data... | |
libatomic | Loading commit data... | |
libbacktrace | Loading commit data... | |
libcc1 | Loading commit data... | |
libcpp | Loading commit data... | |
libdecnumber | Loading commit data... | |
libffi | Loading commit data... | |
libgcc | Loading commit data... | |
libgfortran | Loading commit data... | |
libgo | Loading commit data... | |
libgomp | Loading commit data... | |
libhsail-rt | Loading commit data... | |
libiberty | Loading commit data... | |
libitm | Loading commit data... | |
libobjc | Loading commit data... | |
liboffloadmic | Loading commit data... | |
libphobos | Loading commit data... | |
libquadmath | Loading commit data... | |
libsanitizer | Loading commit data... | |
libssp | Loading commit data... | |
libstdc++-v3 | Loading commit data... | |
libvtv | Loading commit data... | |
lto-plugin | Loading commit data... | |
maintainer-scripts | Loading commit data... | |
zlib | Loading commit data... | |
.dir-locals.el | Loading commit data... | |
.gitattributes | Loading commit data... | |
.gitignore | Loading commit data... | |
ABOUT-NLS | Loading commit data... | |
COPYING | Loading commit data... | |
COPYING.LIB | Loading commit data... | |
COPYING.RUNTIME | Loading commit data... | |
COPYING3 | Loading commit data... | |
COPYING3.LIB | Loading commit data... | |
ChangeLog | Loading commit data... | |
ChangeLog.jit | Loading commit data... | |
ChangeLog.tree-ssa | Loading commit data... | |
MAINTAINERS | Loading commit data... | |
Makefile.def | Loading commit data... | |
Makefile.in | Loading commit data... | |
Makefile.tpl | Loading commit data... | |
README | Loading commit data... | |
ar-lib | Loading commit data... | |
compile | Loading commit data... | |
config-ml.in | Loading commit data... | |
config.guess | Loading commit data... | |
config.rpath | Loading commit data... | |
config.sub | Loading commit data... | |
configure | Loading commit data... | |
configure.ac | Loading commit data... | |
depcomp | Loading commit data... | |
install-sh | Loading commit data... | |
libtool-ldflags | Loading commit data... | |
libtool.m4 | Loading commit data... | |
ltgcc.m4 | Loading commit data... | |
ltmain.sh | Loading commit data... | |
ltoptions.m4 | Loading commit data... | |
ltsugar.m4 | Loading commit data... | |
ltversion.m4 | Loading commit data... | |
lt~obsolete.m4 | Loading commit data... | |
missing | Loading commit data... | |
mkdep | Loading commit data... | |
mkinstalldirs | Loading commit data... | |
move-if-change | Loading commit data... | |
multilib.am | Loading commit data... | |
symlink-tree | Loading commit data... | |
test-driver | Loading commit data... | |
ylwrap | Loading commit data... |