[pushed] c++: using in diagnostics [PR102987]

Message ID 20220429132140.1168266-1-jason@redhat.com
State Committed
Commit a0a2554d7c86c126de85fcbd5bd7e16dbb5a2693
Headers
Series [pushed] c++: using in diagnostics [PR102987] |

Commit Message

Jason Merrill April 29, 2022, 1:21 p.m. UTC
  The decl pretty-printing code wasn't looking at the flags parameter, so we
were printing 'using' in the middle of an expression.

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

	PR c++/102987

gcc/cp/ChangeLog:

	* error.cc (dump_decl) [USING_DECL]: Respect flags.

gcc/testsuite/ChangeLog:

	* g++.dg/diagnostic/using1.C: Check pretty-printing.
---
 gcc/cp/error.cc                          | 18 +++++++++++-------
 gcc/testsuite/g++.dg/diagnostic/using1.C |  1 +
 2 files changed, 12 insertions(+), 7 deletions(-)


base-commit: a282da2243103d79262ca04f5e3a3cc7b9b06935
prerequisite-patch-id: 488a80b552cc74278a93c46df93c5dfe1e019e81
  

Patch

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 2b07136b5ca..53a9073d99b 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -1439,16 +1439,20 @@  dump_decl (cxx_pretty_printer *pp, tree t, int flags)
 
     case USING_DECL:
       {
-	pp_cxx_ws_string (pp, "using");
-	tree scope = USING_DECL_SCOPE (t);
+	if (flags & TFF_DECL_SPECIFIERS)
+	  pp_cxx_ws_string (pp, "using");
 	bool variadic = false;
-	if (PACK_EXPANSION_P (scope))
+	if (!(flags & TFF_UNQUALIFIED_NAME))
 	  {
-	    scope = PACK_EXPANSION_PATTERN (scope);
-	    variadic = true;
+	    tree scope = USING_DECL_SCOPE (t);
+	    if (PACK_EXPANSION_P (scope))
+	      {
+		scope = PACK_EXPANSION_PATTERN (scope);
+		variadic = true;
+	      }
+	    dump_type (pp, scope, flags);
+	    pp_cxx_colon_colon (pp);
 	  }
-	dump_type (pp, scope, flags);
-	pp_cxx_colon_colon (pp);
 	dump_decl (pp, DECL_NAME (t), flags);
 	if (variadic)
 	  pp_cxx_ws_string (pp, "...");
diff --git a/gcc/testsuite/g++.dg/diagnostic/using1.C b/gcc/testsuite/g++.dg/diagnostic/using1.C
index eb4f18d1d8b..4090dd24a60 100644
--- a/gcc/testsuite/g++.dg/diagnostic/using1.C
+++ b/gcc/testsuite/g++.dg/diagnostic/using1.C
@@ -7,6 +7,7 @@  struct a {
 template <typename c> struct d : c {
   using c::e;
   using f = d;
+  // { dg-message "decltype .c::e" "" { target *-*-* } 0 }
   constexpr int g(decltype(e.b())) { return buh; } // { dg-error "buh" }
 };
 struct h {