diff mbox series

[C++] Fix up joust diagnostics (PR c++/89622)

Message ID 20190307192509.GA7611@tucnak
State New
Headers show
Series [C++] Fix up joust diagnostics (PR c++/89622) | expand

Commit Message

Jakub Jelinek March 7, 2019, 7:25 p.m. UTC
Hi!

If no diagnostics is emitted by this pedwarn, whether because of
-Wno-system-headers and location from system headers, or because of -w
etc., we still emit the follow-up messages as if the pedwarn emitted
something.

The following patch makes it conditional on pedwarn returning true (i.e.
that something has been actually printed).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2019-03-07  Jakub Jelinek  <jakub@redhat.com>

	PR c++/89622
	* call.c (joust): Call print_z_candidate only if pedwarn returned
	true.

	* g++.dg/warn/pr89622.C: New test.


	Jakub

Comments

Jason Merrill March 8, 2019, 4:41 a.m. UTC | #1
On 3/7/19 2:25 PM, Jakub Jelinek wrote:
> Hi!
> 
> If no diagnostics is emitted by this pedwarn, whether because of
> -Wno-system-headers and location from system headers, or because of -w
> etc., we still emit the follow-up messages as if the pedwarn emitted
> something.
> 
> The following patch makes it conditional on pedwarn returning true (i.e.
> that something has been actually printed).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2019-03-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/89622
> 	* call.c (joust): Call print_z_candidate only if pedwarn returned
> 	true.

OK.

Jason
diff mbox series

Patch

--- gcc/cp/call.c.jj	2019-03-06 19:45:40.369751609 +0100
+++ gcc/cp/call.c	2019-03-07 14:51:20.062959019 +0100
@@ -10954,12 +10954,14 @@  tweak:
 	  if (warn)
 	    {
 	      auto_diagnostic_group d;
-	      pedwarn (input_location, 0,
-	      "ISO C++ says that these are ambiguous, even "
-	      "though the worst conversion for the first is better than "
-	      "the worst conversion for the second:");
-	      print_z_candidate (input_location, _("candidate 1:"), w);
-	      print_z_candidate (input_location, _("candidate 2:"), l);
+	      if (pedwarn (input_location, 0,
+			   "ISO C++ says that these are ambiguous, even "
+			   "though the worst conversion for the first is "
+			   "better than the worst conversion for the second:"))
+		{
+		  print_z_candidate (input_location, _("candidate 1:"), w);
+		  print_z_candidate (input_location, _("candidate 2:"), l);
+		}
 	    }
 	  else
 	    add_warning (w, l);
--- gcc/testsuite/g++.dg/warn/pr89622.C.jj	2019-03-07 14:51:57.691344552 +0100
+++ gcc/testsuite/g++.dg/warn/pr89622.C	2019-03-07 14:48:24.167831364 +0100
@@ -0,0 +1,27 @@ 
+// PR c++/89622
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-system-headers -w" }
+// { dg-bogus "says that these are ambiguous" "" { target *-*-* } 0 }
+// { dg-bogus "candidate 1" "" { target *-*-* } 0 }
+// { dg-bogus "candidate 2" "" { target *-*-* } 0 }
+
+# 3 "pr89622.h" 3
+template<typename T>
+struct X
+{
+  X() { }
+  template<typename U> X(int, U&&) { }
+  template<typename U> X(char, const X<U>&) { }
+};
+
+template<typename T>
+X<T> wrap_X(X<T> x)
+{
+  return X<T>('a', x);
+}
+
+int main()
+{
+  X<void> x;
+  wrap_X(x);
+}