diff options
author | Patrick Palka <ppalka@redhat.com> | 2022-03-09 08:42:32 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2022-03-09 08:42:32 -0500 |
commit | e32869a17b788bee9ca782b174a546b1db17b5ea (patch) | |
tree | 0f76ecbece601e5557fb797850b3d603a0a6103a /gcc/cp/decl.cc | |
parent | fe548eb8436f3906e6a3c6e3e8707d24e60ec0fa (diff) | |
download | gcc-e32869a17b788bee9ca782b174a546b1db17b5ea.zip gcc-e32869a17b788bee9ca782b174a546b1db17b5ea.tar.gz gcc-e32869a17b788bee9ca782b174a546b1db17b5ea.tar.bz2 |
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.
Diffstat (limited to 'gcc/cp/decl.cc')
-rw-r--r-- | gcc/cp/decl.cc | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 48763c4..992e3838 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -7962,6 +7962,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (type == error_mark_node) return; + if (VAR_P (decl) && is_copy_initialization (init)) + flags |= LOOKUP_ONLYCONVERTING; + /* Warn about register storage specifiers except when in GNU global or local register variable extension. */ if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE) |