[C++] Check permerror return value

Message ID 2d32996e-3e2f-87af-d9dd-268c6f167337@oracle.com
State New
Headers show
Series
  • [C++] Check permerror return value
Related show

Commit Message

Paolo Carlini July 16, 2018, 11:46 a.m.
Hi,

over the last weeks, while working on various diagnostic issues, I 
noticed a few defective permerror + inform pairs. Tested x86_64-linux.

Thanks, Paolo.

////////////////////
/cp
2018-07-16  Paolo Carlini  <paolo.carlini@oracle.com>

	* class.c (resolve_address_of_overloaded_function): Don't emit an
	inform if the matching permerror returns false.
	* pt.c (check_specialization_namespace): Likewise.

/testsuite
2018-07-16  Paolo Carlini  <paolo.carlini@oracle.com>

	* g++.dg/template/spec40.C: New.
	* g++.dg/parse/ptrmem8.C: Likewise.

Comments

Nathan Sidwell July 16, 2018, 4:41 p.m. | #1
On 07/16/2018 07:46 AM, Paolo Carlini wrote:
> Hi,

> 

> over the last weeks, while working on various diagnostic issues, I 

> noticed a few defective permerror + inform pairs. Tested x86_64-linux.

> 


ok, thanks


-- 
Nathan Sidwell

Patch

Index: cp/class.c
===================================================================
--- cp/class.c	(revision 262687)
+++ cp/class.c	(working copy)
@@ -7919,10 +7919,11 @@  resolve_address_of_overloaded_function (tree targe
       if (!(complain & tf_error))
 	return error_mark_node;
 
-      permerror (input_location, "assuming pointer to member %qD", fn);
-      if (!explained)
+      if (permerror (input_location, "assuming pointer to member %qD", fn)
+	  && !explained)
 	{
-	  inform (input_location, "(a pointer to member can only be formed with %<&%E%>)", fn);
+	  inform (input_location, "(a pointer to member can only be "
+		  "formed with %<&%E%>)", fn);
 	  explained = 1;
 	}
     }
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 262687)
+++ cp/pt.c	(working copy)
@@ -800,10 +800,10 @@  check_specialization_namespace (tree tmpl)
     return true;
   else
     {
-      permerror (input_location,
-		 "specialization of %qD in different namespace", tmpl);
-      inform (DECL_SOURCE_LOCATION (tmpl),
-	      "  from definition of %q#D", tmpl);
+      if (permerror (input_location,
+		     "specialization of %qD in different namespace", tmpl))
+	inform (DECL_SOURCE_LOCATION (tmpl),
+		"  from definition of %q#D", tmpl);
       return false;
     }
 }
Index: testsuite/g++.dg/template/spec40.C
===================================================================
--- testsuite/g++.dg/template/spec40.C	(nonexistent)
+++ testsuite/g++.dg/template/spec40.C	(working copy)
@@ -0,0 +1,12 @@ 
+// { dg-options "-fpermissive -w" }
+
+namespace N {
+  template <typename T>
+  struct S {
+    void f() {}  // { dg-bogus "from definition" }
+  };
+}
+
+namespace K {
+  template <> void N::S<char>::f() {}
+}
Index: testsuite/g++.dg/parse/ptrmem8.C
===================================================================
--- testsuite/g++.dg/parse/ptrmem8.C	(nonexistent)
+++ testsuite/g++.dg/parse/ptrmem8.C	(working copy)
@@ -0,0 +1,15 @@ 
+// { dg-options "-fpermissive -w" }
+
+struct A
+{
+  template<int> void foo()
+  {
+    void (A::* fp)();
+    fp = A::foo<0>;  // { dg-bogus "pointer to member" }
+  }
+};
+
+void bar()
+{
+  A().foo<0>();
+}