public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: using in diagnostics [PR102987]
@ 2022-04-15  1:00 Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-04-15  1:00 UTC (permalink / raw)
  To: gcc-patches

The expression pretty-printing code crashed on a location wrapper with no
type, and didn't know what to do with a USING_DECL.

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

	PR c++/102987

gcc/cp/ChangeLog:

	* error.cc (dump_expr): Handle USING_DECL.
	[VIEW_CONVERT_EXPR]: Just look through location wrapper.

gcc/testsuite/ChangeLog:

	* g++.dg/diagnostic/using1.C: New test.
---
 gcc/cp/error.cc                          |  8 ++++++++
 gcc/testsuite/g++.dg/diagnostic/using1.C | 16 ++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/diagnostic/using1.C

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index e76842e1a2a..1e944ca3f75 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -2203,6 +2203,7 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
     case WILDCARD_DECL:
     case OVERLOAD:
     case TYPE_DECL:
+    case USING_DECL:
     case IDENTIFIER_NODE:
       dump_decl (pp, t, ((flags & ~(TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE
                                     |TFF_TEMPLATE_HEADER))
@@ -2584,6 +2585,13 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
     case VIEW_CONVERT_EXPR:
       {
 	tree op = TREE_OPERAND (t, 0);
+
+	if (location_wrapper_p (t))
+	  {
+	    dump_expr (pp, op, flags);
+	    break;
+	  }
+
 	tree ttype = TREE_TYPE (t);
 	tree optype = TREE_TYPE (op);
 
diff --git a/gcc/testsuite/g++.dg/diagnostic/using1.C b/gcc/testsuite/g++.dg/diagnostic/using1.C
new file mode 100644
index 00000000000..eb4f18d1d8b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/diagnostic/using1.C
@@ -0,0 +1,16 @@
+// PR c++/102987
+// { dg-do compile { target c++11 } }
+
+struct a {
+  bool b();
+};
+template <typename c> struct d : c {
+  using c::e;
+  using f = d;
+  constexpr int g(decltype(e.b())) { return buh; } // { dg-error "buh" }
+};
+struct h {
+  a e;
+};
+using i = d<h>;
+auto j = i{}.g(1);

base-commit: 031bd52e482a53314d3dfac2d375c1033a6b7031
-- 
2.27.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [pushed] c++: using in diagnostics [PR102987]
@ 2022-04-29 13:21 Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-04-29 13:21 UTC (permalink / raw)
  To: gcc-patches

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(-)

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 {

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-29 13:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-15  1:00 [pushed] c++: using in diagnostics [PR102987] Jason Merrill
2022-04-29 13:21 Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).