diff mbox series

C++ PATCH to fix naked inform call for strong using directive

Message ID 20190520155635.GH7979@redhat.com
State New
Headers show
Series C++ PATCH to fix naked inform call for strong using directive | expand

Commit Message

Marek Polacek May 20, 2019, 3:56 p.m. UTC
This patch fixes a naked inform call that can be seen with -w.

While at it, I added missing quotes; I'm surprisesd this wasn't fixed by the
recent patch Martin submitted. 

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

2019-05-20  Marek Polacek  <polacek@redhat.com>

	* name-lookup.c (finish_using_directive): Don't issue inform() if the
	warning didn't trigger.  Add quoting.

	* g++.dg/lookup/strong-using2.C: New test.

Comments

Jason Merrill May 20, 2019, 5:44 p.m. UTC | #1
On 5/20/19 11:56 AM, Marek Polacek wrote:
> This patch fixes a naked inform call that can be seen with -w.
> 
> While at it, I added missing quotes; I'm surprisesd this wasn't fixed by the
> recent patch Martin submitted.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

OK.  We might also change "may" to "can" in the inform.

Jason
Marek Polacek May 20, 2019, 7:03 p.m. UTC | #2
On Mon, May 20, 2019 at 01:44:47PM -0400, Jason Merrill wrote:
> On 5/20/19 11:56 AM, Marek Polacek wrote:
> > This patch fixes a naked inform call that can be seen with -w.
> > 
> > While at it, I added missing quotes; I'm surprisesd this wasn't fixed by the
> > recent patch Martin submitted.
> > 
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> 
> OK.  We might also change "may" to "can" in the inform.

Done in the following, thanks.

Bootstrapped/regtested on x86_64-linux, applying to trunk.

2019-05-20  Marek Polacek  <polacek@redhat.com>

	* name-lookup.c (finish_using_directive): Don't issue inform() if the
	warning didn't trigger.  Add quoting.  Tweak the inform message.

	* g++.dg/lookup/strong-using2.C: New test.

diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
index f7952eebe0c..476ba509231 100644
--- gcc/cp/name-lookup.c
+++ gcc/cp/name-lookup.c
@@ -7258,10 +7258,10 @@ finish_using_directive (tree target, tree attribs)
 	if (current_binding_level->kind == sk_namespace
 	    && is_attribute_p ("strong", name))
 	  {
-	    warning (0, "strong using directive no longer supported");
-	    if (CP_DECL_CONTEXT (target) == current_namespace)
+	    if (warning (0, "%<strong%> using directive no longer supported")
+		&& CP_DECL_CONTEXT (target) == current_namespace)
 	      inform (DECL_SOURCE_LOCATION (target),
-		      "you may use an inline namespace instead");
+		      "you can use an inline namespace instead");
 	  }
 	else
 	  warning (OPT_Wattributes, "%qD attribute directive ignored", name);
diff --git gcc/testsuite/g++.dg/lookup/strong-using2.C gcc/testsuite/g++.dg/lookup/strong-using2.C
new file mode 100644
index 00000000000..17284949645
--- /dev/null
+++ gcc/testsuite/g++.dg/lookup/strong-using2.C
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++11 } }
+// { dg-options "-w" }
+
+namespace A
+{
+  namespace B // { dg-bogus "inline namespace" }
+  {
+  }
+
+  using namespace B __attribute__ ((strong)); // { dg-bogus "no longer supported" }
+}
diff mbox series

Patch

diff --git gcc/cp/name-lookup.c gcc/cp/name-lookup.c
index f7952eebe0c..fe3d5414e7c 100644
--- gcc/cp/name-lookup.c
+++ gcc/cp/name-lookup.c
@@ -7258,8 +7258,8 @@  finish_using_directive (tree target, tree attribs)
 	if (current_binding_level->kind == sk_namespace
 	    && is_attribute_p ("strong", name))
 	  {
-	    warning (0, "strong using directive no longer supported");
-	    if (CP_DECL_CONTEXT (target) == current_namespace)
+	    if (warning (0, "%<strong%> using directive no longer supported")
+		&& CP_DECL_CONTEXT (target) == current_namespace)
 	      inform (DECL_SOURCE_LOCATION (target),
 		      "you may use an inline namespace instead");
 	  }
diff --git gcc/testsuite/g++.dg/lookup/strong-using2.C gcc/testsuite/g++.dg/lookup/strong-using2.C
new file mode 100644
index 00000000000..0c497245df0
--- /dev/null
+++ gcc/testsuite/g++.dg/lookup/strong-using2.C
@@ -0,0 +1,11 @@ 
+// { dg-do compile { target c++11 } }
+// { dg-options "-w" }
+
+namespace A
+{
+  namespace B // { dg-bogus "inline namespace" }
+  {
+  }
+
+  using namespace B __attribute__ ((strong)); // { dg-bogus "no longer supported" }
+}