From 67378ae56d23c9109e6fe1176d40dcee23e422aa Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 20 Feb 2017 06:03:45 +0000 Subject: [PATCH] PR c++/79503 - inherited ctor taking base class * call.c (add_function_candidate): Also check that DECL_INHERITED_CTOR_BASE is reference-related to the parameter type. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@245586 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 4 +++- gcc/testsuite/g++.dg/cpp0x/inh-ctor26.C | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/inh-ctor26.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 20c7eed3bcb..9b071ebef9e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-02-19 Jason Merrill + + PR c++/79503 - inherited ctor taking base class + * call.c (add_function_candidate): Also check that + DECL_INHERITED_CTOR_BASE is reference-related to the parameter type. + 2017-02-19 Paolo Carlini PR c++/79380 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 4ef444b761b..d6d3a8f61d9 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2057,7 +2057,9 @@ add_function_candidate (struct z_candidate **candidates, { tree ptype = non_reference (TREE_VALUE (parmlist)); tree dtype = DECL_CONTEXT (fn); - if (reference_related_p (ptype, dtype)) + tree btype = DECL_INHERITED_CTOR_BASE (fn); + if (reference_related_p (ptype, dtype) + && reference_related_p (btype, ptype)) { viable = false; reason = inherited_ctor_rejection (); diff --git a/gcc/testsuite/g++.dg/cpp0x/inh-ctor26.C b/gcc/testsuite/g++.dg/cpp0x/inh-ctor26.C new file mode 100644 index 00000000000..e1e6b9e0418 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/inh-ctor26.C @@ -0,0 +1,21 @@ +// PR c++/79503 +// { dg-do compile { target c++11 } } + +struct payload {}; + +struct base: private payload { + base(payload) {} +}; + +struct derived: base { + using base::base; +}; + +int main() +{ + payload data; + // error: no matching function for call to 'derived::derived(payload&)' + // note: candidate: base::base(payload) + // note: an inherited constructor is not a candidate for initialization from an expression of the same or derived type + derived demo(data); +} -- 2.11.4.GIT