]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: detecting copy-init context during CTAD [PR102137]
authorPatrick Palka <ppalka@redhat.com>
Wed, 9 Mar 2022 13:42:32 +0000 (08:42 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 9 Mar 2022 13:42:32 +0000 (08:42 -0500)
commite32869a17b788bee9ca782b174a546b1db17b5ea
tree0f76ecbece601e5557fb797850b3d603a0a6103a
parentfe548eb8436f3906e6a3c6e3e8707d24e60ec0fa
c++: detecting copy-init context during CTAD [PR102137]

Here we're failing to communicate to cp_finish_decl from tsubst_expr
that we're in a copy-initialization context (via the LOOKUP_ONLYCONVERTING
flag), which causes us to always consider explicit deduction guides when
performing CTAD for a templated variable initializer.

It turns out this bug also affects consideration of explicit conversion
operators for the same reason.  But consideration of explicit constructors
seems unaffacted thanks to code in build_aggr_init that sets
LOOKUP_ONLYCONVERTING when the initializer represents copy-initialization.

So this patch fixes this by making cp_finish_decl set LOOKUP_ONLYCONVERTING
just like build_aggr_init does, by inspecting the initializer, so that
callers don't need to explicitly pass this flag appropriately.

PR c++/102137
PR c++/87820

gcc/cp/ChangeLog:

* cp-tree.h (is_copy_initialization): Declare.
* decl.cc (cp_finish_decl): Set LOOKUP_ONLYCONVERTING
when is_copy_initialization is true.
* init.cc (build_aggr_init): Split out copy-initialization
check into ...
(is_copy_initialization): ... here.
* pt.cc (instantiate_decl): Pass 0 instead of
LOOKUP_ONLYCONVERTING as flags to cp_finish_decl.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/explicit15.C: New test.
* g++.dg/cpp1z/class-deduction108.C: New test.
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/init.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/explicit15.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/class-deduction108.C [new file with mode: 0644]