* C++ PATCH for c++/79503 (inherited ctor taking base class)
@ 2017-02-20 5:48 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2017-02-20 5:48 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
In the old inheriting constructor scheme, copy constructors were not
inherited. In the new scheme we needed a rule to get a similar
effect; I proposed that an inherited constructor should not be viable
if it has a single parameter of a type reference-related to the
derived type. Richard Smith proposed a further refinement that this
would apply only if the base type is also reference-related to the
parameter type. This testcase demonstrates why this refinement is
needed.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 79503.diff --]
[-- Type: text/plain, Size: 1608 bytes --]
commit 5e1645da2601d0c31a2fd0a5687224d6e3087824
Author: Jason Merrill <jason@redhat.com>
Date: Sun Feb 19 16:22:43 2017 -0500
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.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4ef444b..d6d3a8f 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 0000000..e1e6b9e
--- /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);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-02-20 5:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-20 5:48 C++ PATCH for c++/79503 (inherited ctor taking base class) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).