diff mbox

C++ PATCH for c++/49058 (different SFINAE with -pedantic)

Message ID 4DDA7765.3030103@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 23, 2011, 3:04 p.m. UTC
Normally, we try to be somewhat permissive about overload resolution, 
accepting near-matches when available in order to give better 
diagnostics about why they aren't complete matches.  But this doesn't 
apply in templates, since we don't actually perform the conversions that 
would generate the diagnostics, and in SFINAE context it's important to 
be strictly conforming.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit b064aafb08a8c85cfb84c839e21cf704adb42b2d
Author: Jason Merrill <jason@redhat.com>
Date:   Sun May 22 22:18:07 2011 -0400

    	PR c++/49058
    	* call.c (splice_viable): Be strict in templates.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 972dca3..8503f5e 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3009,6 +3009,11 @@  splice_viable (struct z_candidate *cands,
   struct z_candidate **last_viable;
   struct z_candidate **cand;
 
+  /* Be strict inside templates, since build_over_call won't actually
+     do the conversions to get pedwarns.  */
+  if (processing_template_decl)
+    strict_p = true;
+
   viable = NULL;
   last_viable = &viable;
   *any_viable_p = false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/sfinae24.C b/gcc/testsuite/g++.dg/cpp0x/sfinae24.C
new file mode 100644
index 0000000..3e1d2e7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/sfinae24.C
@@ -0,0 +1,29 @@ 
+// PR c++/49058
+// This error is not subject to SFINAE because it doesn't happen in the
+// deduction context.
+// { dg-options -std=c++0x }
+// { dg-prune-output "note" }
+
+template<typename T> T val();
+
+struct F1
+{
+    void operator()();
+};
+
+template<typename F>
+struct Bind
+{
+    template<typename R
+      = decltype( val<F>()( ) )>
+    R f();
+
+    template<typename R
+      = decltype( val<const F>()( ) )>
+    R f() const;		// { dg-error "no match" }
+};
+
+int main()
+{
+  Bind<F1> b;
+}