diff mbox series

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

Message ID 20220415010023.3512094-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: using in diagnostics [PR102987] | expand

Commit Message

Jason Merrill April 15, 2022, 1 a.m. UTC
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


base-commit: 031bd52e482a53314d3dfac2d375c1033a6b7031
diff mbox series

Patch

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