public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-86] c++: Fix pretty printing pointer to function type [PR98767]
@ 2021-04-23 12:47 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-04-23 12:47 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:87fc34a461cf362947a430d8a241f653fd83bc7b
commit r12-86-g87fc34a461cf362947a430d8a241f653fd83bc7b
Author: Patrick Palka <ppalka@redhat.com>
Date: Fri Apr 23 08:47:02 2021 -0400
c++: Fix pretty printing pointer to function type [PR98767]
When pretty printing a pointer to function type,
pp_cxx_parameter_declaration_clause ends up always outputting an empty
function parameter list because the loop that outputs the list iterates
over 'args' instead of 'types', and 'args' is empty when a FUNCTION_TYPE
is passed to this routine (as opposed to a FUNCTION_DECL).
This patch fixes this by making the loop iterate over 'types' instead.
This patch also moves the retrofitted chain-of-PARM_DECLs printing from
here to pp_cxx_requires_expr, the only caller that uses it. Doing so
lets us easily output the trailing '...' in the parameter list of a
variadic function, which this patch also implements.
gcc/cp/ChangeLog:
PR c++/98767
* cxx-pretty-print.c (pp_cxx_parameter_declaration_clause):
Adjust parameter list loop to iterate over 'types' instead of
'args'. Output the trailing '...' for a variadic function.
Remove PARM_DECL support.
(pp_cxx_requires_expr): Pretty print the parameter list directly
instead of going through pp_cxx_parameter_declaration_clause.
gcc/testsuite/ChangeLog:
PR c++/98767
* g++.dg/concepts/diagnostic17.C: New test.
Diff:
---
gcc/cp/cxx-pretty-print.c | 47 +++++++++++++++++-----------
gcc/testsuite/g++.dg/concepts/diagnostic17.C | 17 ++++++++++
2 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index a22eea5239c..3709d0f2b2d 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -1537,38 +1537,36 @@ pp_cxx_parameter_declaration (cxx_pretty_printer *pp, tree t)
static void
pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
{
- tree args;
- tree types;
- bool abstract;
-
- // For a requires clause or the explicit printing of a parameter list
- // we expect T to be a chain of PARM_DECLs. Otherwise, the list of
- // args and types are taken from the function decl T.
- if (TREE_CODE (t) == PARM_DECL)
+ gcc_assert (FUNC_OR_METHOD_TYPE_P (t) || TREE_CODE (t) == FUNCTION_DECL);
+ tree types, args;
+ if (TYPE_P (t))
{
- args = t;
- types = t;
- abstract = false;
+ types = TYPE_ARG_TYPES (t);
+ args = NULL_TREE;
}
else
{
- bool type_p = TYPE_P (t);
- args = type_p ? NULL : FUNCTION_FIRST_USER_PARM (t);
- types = type_p ? TYPE_ARG_TYPES (t) : FUNCTION_FIRST_USER_PARMTYPE (t);
- abstract = args == NULL || pp->flags & pp_c_flag_abstract;
+ types = FUNCTION_FIRST_USER_PARMTYPE (t);
+ args = FUNCTION_FIRST_USER_PARM (t);
}
- bool first = true;
+ bool abstract = !args || (pp->flags & pp_c_flag_abstract);
/* Skip artificial parameter for non-static member functions. */
if (TREE_CODE (t) == METHOD_TYPE)
types = TREE_CHAIN (types);
+ bool first = true;
pp_cxx_left_paren (pp);
- for (; args; args = TREE_CHAIN (args), types = TREE_CHAIN (types))
+ for (; types != void_list_node; types = TREE_CHAIN (types))
{
if (!first)
pp_cxx_separate_with (pp, ',');
first = false;
+ if (!types)
+ {
+ pp_cxx_ws_string (pp, "...");
+ break;
+ }
pp_cxx_parameter_declaration (pp, abstract ? TREE_VALUE (types) : args);
if (!abstract && pp->flags & pp_cxx_flag_default_argument)
{
@@ -1577,6 +1575,8 @@ pp_cxx_parameter_declaration_clause (cxx_pretty_printer *pp, tree t)
pp_cxx_whitespace (pp);
pp->assignment_expression (TREE_PURPOSE (types));
}
+ if (!abstract)
+ args = TREE_CHAIN (args);
}
pp_cxx_right_paren (pp);
}
@@ -2775,9 +2775,18 @@ void
pp_cxx_requires_expr (cxx_pretty_printer *pp, tree t)
{
pp_string (pp, "requires");
- if (tree parms = TREE_OPERAND (t, 0))
+ if (tree parms = REQUIRES_EXPR_PARMS (t))
{
- pp_cxx_parameter_declaration_clause (pp, parms);
+ bool first = true;
+ pp_cxx_left_paren (pp);
+ for (; parms; parms = TREE_CHAIN (parms))
+ {
+ if (!first)
+ pp_cxx_separate_with (pp, ',' );
+ first = false;
+ pp_cxx_parameter_declaration (pp, parms);
+ }
+ pp_cxx_right_paren (pp);
pp_cxx_whitespace (pp);
}
pp_cxx_requirement_body (pp, TREE_OPERAND (t, 1));
diff --git a/gcc/testsuite/g++.dg/concepts/diagnostic17.C b/gcc/testsuite/g++.dg/concepts/diagnostic17.C
new file mode 100644
index 00000000000..49d5733faea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/diagnostic17.C
@@ -0,0 +1,17 @@
+// PR c++/98767
+// { dg-do compile { target c++20 } }
+
+template <typename Function, typename... Args>
+concept Callable = requires(Function func, Args... args) { func(args...); };
+
+static_assert(Callable<int(*)(), bool>); // { dg-error "failed" }
+// { dg-message {Function = int \(\*\)\(\)} "" { target *-*-* } 5 }
+
+static_assert(Callable<char(*)(int*), bool>); // { dg-error "failed" }
+// { dg-message {Function = char \(\*\)\(int\*\)} "" { target *-*-* } 5 }
+
+static_assert(Callable<short(*)(int*, int), bool>); // { dg-error "failed" }
+// { dg-message {Function = short int \(\*\)\(int\*, int\)} "" { target *-*-* } 5 }
+
+static_assert(Callable<long(*)(int*, int, ...), bool>); // { dg-error "failed" }
+// { dg-message {Function = long int \(\*\)\(int\*, int, \.\.\.\)} "" { target *-*-* } 5 }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-23 12:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 12:47 [gcc r12-86] c++: Fix pretty printing pointer to function type [PR98767] Patrick Palka
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).