* C++ PATCH to explicit conversion ops handling
@ 2009-10-23 18:26 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2009-10-23 18:26 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 319 bytes --]
Discussion of core issue 899 concluded that the way I made explicit
conversion ops to class type work was the way to go, just with a small
restriction that it only apply when the copy constructor is invoked with
a single argument. So I've adjusted the implementation.
Tested x86_64-pc-linux-gnu, applied to trunk.
[-- Attachment #2: exp-conv2.patch --]
[-- Type: text/x-patch, Size: 1285 bytes --]
commit 16219f7fd77e362d9aa4e717529cd42a9f126153
Author: Jason Merrill <jason@redhat.com>
Date: Thu Oct 22 11:09:42 2009 -0700
Core issue 899
* call.c (add_function_candidate): Only permit explicit conversion
ops if copy ctor was called with a single argument.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index fe74d15..4542804 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -1631,7 +1631,8 @@ add_function_candidate (struct z_candidate **candidates,
parmtype = build_pointer_type (parmtype);
}
- if (ctype && i == 0 && DECL_COPY_CONSTRUCTOR_P (fn))
+ if (ctype && i == 0 && DECL_COPY_CONSTRUCTOR_P (fn)
+ && (len-skip == 1))
{
/* Hack: Direct-initialize copy parm (i.e. suppress
LOOKUP_ONLYCONVERTING) to make explicit conversion ops
diff --git a/gcc/testsuite/g++.dg/cpp0x/explicit4.C b/gcc/testsuite/g++.dg/cpp0x/explicit4.C
new file mode 100644
index 0000000..74726a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/explicit4.C
@@ -0,0 +1,17 @@
+// Negative explicit conv test.
+// { dg-options "-std=c++0x" }
+
+struct A {
+ A(const A&, int = 0); // { dg-message "candidates" }
+};
+struct B
+{
+ explicit operator A();
+};
+
+int main()
+{
+ B b;
+ (A(b)); // OK
+ (A(b,1)); // { dg-error "no match" }
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-10-23 18:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-23 18:26 C++ PATCH to explicit conversion ops handling 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).