[gcc(refs/users/marxin/heads/marxin-gcc-benchmark-branch)] c++: Improve dump_decl for standard concepts

Martin Liska marxin@gcc.gnu.org
Mon Mar 30 10:57:49 GMT 2020


https://gcc.gnu.org/g:91f4fc40bcf666eb57d566198981dc8e8eff9ccb

commit 91f4fc40bcf666eb57d566198981dc8e8eff9ccb
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Feb 10 10:48:27 2020 -0500

    c++: Improve dump_decl for standard concepts
    
    This patch improves the pretty printing of standard concept definitions in error
    messages.  In particular, standard concepts are now printed qualified whenever
    appropriate, and the "concept" specifier is printed only when the
    TFF_DECL_SPECIFIERS flag is specified.
    
    In the below test, the first error message changes from
      9:15: error: ‘b’ was not declared in this scope; did you mean ‘concept b’?
    to
      9:15: error: ‘b’ was not declared in this scope; did you mean ‘a::b’?
    
    gcc/cp/ChangeLog:
    
            * error.c (dump_decl) [CONCEPT_DECL]: Use dump_simple_decl.
            (dump_simple_decl): Handle standard concept definitions as well as
            variable concept definitions.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts6.C: New test.

Diff:
---
 gcc/cp/ChangeLog                       |  6 ++++++
 gcc/cp/error.c                         | 18 ++++++++----------
 gcc/testsuite/ChangeLog                |  4 ++++
 gcc/testsuite/g++.dg/cpp2a/concepts6.C | 18 ++++++++++++++++++
 4 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a8b447b5740..5a6e3564eda 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-12  Patrick Palka  <ppalka@redhat.com>
+
+	* error.c (dump_decl) [CONCEPT_DECL]: Use dump_simple_decl.
+	(dump_simple_decl): Handle standard concept definitions as well as
+	variable concept definitions.
+
 2020-02-10  Jakub Jelinek  <jakub@redhat.com>
 
 	PR other/93641
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 8ec1653d87a..cc51b6ffe13 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1037,14 +1037,13 @@ dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags)
 
   if (flags & TFF_DECL_SPECIFIERS)
     {
-      if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t))
-        {
-	  if (DECL_LANG_SPECIFIC (t) && DECL_DECLARED_CONCEPT_P (t))
-	    pp_cxx_ws_string (pp, "concept");
-	  else
-	    pp_cxx_ws_string (pp, "constexpr");
-	}
-      dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME);
+      if (concept_definition_p (t))
+	pp_cxx_ws_string (pp, "concept");
+      else if (VAR_P (t) && DECL_DECLARED_CONSTEXPR_P (t))
+	pp_cxx_ws_string (pp, "constexpr");
+
+      if (!standard_concept_p (t))
+	dump_type_prefix (pp, type, flags & ~TFF_UNQUALIFIED_NAME);
       pp_maybe_space (pp);
     }
   if (! (flags & TFF_UNQUALIFIED_NAME)
@@ -1296,8 +1295,7 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags)
       break;
 
     case CONCEPT_DECL:
-      pp_cxx_ws_string (pp, "concept");
-      dump_decl_name (pp, DECL_NAME (t), flags);
+      dump_simple_decl (pp, t, TREE_TYPE (t), flags);
       break;
 
     case WILDCARD_DECL:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 290bd8afdfa..5f31ceb04de 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2020-02-12  Patrick Palka  <ppalka@redhat.com>
+
+	* g++.dg/cpp2a/concepts6.C: New test.
+
 2020-02-10  David Malcolm  <dmalcolm@redhat.com>
 
 	PR analyzer/93350
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts6.C b/gcc/testsuite/g++.dg/cpp2a/concepts6.C
new file mode 100644
index 00000000000..d69628b0318
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts6.C
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++2a } }
+
+namespace a
+{
+  template<typename = int>
+    concept b = true; // { dg-message ".a::b. declared here" }
+}
+
+static_assert(b); // { dg-error "did you mean .a::b." }
+
+namespace c
+{
+  template<typename>
+    concept b = true; // { dg-message "concept c::b." }
+
+  template<typename>
+    concept b = true; // { dg-error "concept c::b." }
+}


More information about the Gcc-cvs mailing list