* [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P
@ 2023-11-30 5:00 Jason Merrill
2023-12-01 3:50 ` [PATCH] c++: lambda capture and explicit object parm Jason Merrill
2023-12-01 19:03 ` [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P Patrick Palka
0 siblings, 2 replies; 3+ messages in thread
From: Jason Merrill @ 2023-11-30 5:00 UTC (permalink / raw)
To: gcc-patches; +Cc: waffl3x
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
In review of the deducing 'this' patch it came up that LAMBDA_EXPR_MUTABLE_P
doesn't make sense for a lambda with an explicit object parameter. And it
was never necessary, so let's remove it.
gcc/cp/ChangeLog:
* cp-tree.h (LAMBDA_EXPR_MUTABLE_P): Remove.
* cp-tree.def: Remove documentation.
* lambda.cc (build_lambda_expr): Remove reference.
* parser.cc (cp_parser_lambda_declarator_opt): Likewise.
* pt.cc (tsubst_lambda_expr): Likewise.
* ptree.cc (cxx_print_lambda_node): Likewise.
* semantics.cc (capture_decltype): Get the object quals
from the object instead.
---
gcc/cp/cp-tree.h | 5 -----
gcc/cp/lambda.cc | 1 -
gcc/cp/parser.cc | 1 -
gcc/cp/pt.cc | 1 -
gcc/cp/ptree.cc | 2 --
gcc/cp/semantics.cc | 9 ++++++---
gcc/cp/cp-tree.def | 3 +--
7 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 5614b71eed4..964af1ddd85 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -461,7 +461,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
TYPENAME_IS_CLASS_P (in TYPENAME_TYPE)
STMT_IS_FULL_EXPR_P (in _STMT)
TARGET_EXPR_LIST_INIT_P (in TARGET_EXPR)
- LAMBDA_EXPR_MUTABLE_P (in LAMBDA_EXPR)
DECL_FINAL_P (in FUNCTION_DECL)
QUALIFIED_NAME_IS_TEMPLATE (in SCOPE_REF)
CONSTRUCTOR_IS_DEPENDENT (in CONSTRUCTOR)
@@ -1478,10 +1477,6 @@ enum cp_lambda_default_capture_mode_type {
#define LAMBDA_EXPR_CAPTURES_THIS_P(NODE) \
LAMBDA_EXPR_THIS_CAPTURE(NODE)
-/* Predicate tracking whether the lambda was declared 'mutable'. */
-#define LAMBDA_EXPR_MUTABLE_P(NODE) \
- TREE_LANG_FLAG_1 (LAMBDA_EXPR_CHECK (NODE))
-
/* True iff uses of a const variable capture were optimized away. */
#define LAMBDA_EXPR_CAPTURE_OPTIMIZED(NODE) \
TREE_LANG_FLAG_2 (LAMBDA_EXPR_CHECK (NODE))
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index 34d0190a89b..be8d240944d 100644
--- a/gcc/cp/lambda.cc
+++ b/gcc/cp/lambda.cc
@@ -44,7 +44,6 @@ build_lambda_expr (void)
LAMBDA_EXPR_THIS_CAPTURE (lambda) = NULL_TREE;
LAMBDA_EXPR_REGEN_INFO (lambda) = NULL_TREE;
LAMBDA_EXPR_PENDING_PROXIES (lambda) = NULL;
- LAMBDA_EXPR_MUTABLE_P (lambda) = false;
return lambda;
}
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 2464d1a0783..1826b6175f5 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -11770,7 +11770,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
if (lambda_specs.storage_class == sc_mutable)
{
- LAMBDA_EXPR_MUTABLE_P (lambda_expr) = 1;
quals = TYPE_UNQUALIFIED;
}
else if (lambda_specs.storage_class == sc_static)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c18718b319d..00a808bf323 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -19341,7 +19341,6 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
= LAMBDA_EXPR_LOCATION (t);
LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (r)
= LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (t);
- LAMBDA_EXPR_MUTABLE_P (r) = LAMBDA_EXPR_MUTABLE_P (t);
if (tree ti = LAMBDA_EXPR_REGEN_INFO (t))
LAMBDA_EXPR_REGEN_INFO (r)
= build_template_info (t, add_to_template_args (TI_ARGS (ti),
diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc
index 32c5b5280dc..d1f58921fab 100644
--- a/gcc/cp/ptree.cc
+++ b/gcc/cp/ptree.cc
@@ -265,8 +265,6 @@ cxx_print_identifier (FILE *file, tree node, int indent)
void
cxx_print_lambda_node (FILE *file, tree node, int indent)
{
- if (LAMBDA_EXPR_MUTABLE_P (node))
- fprintf (file, " /mutable");
fprintf (file, " default_capture_mode=[");
switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
{
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 04b0540599a..36b57ac9524 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12792,9 +12792,12 @@ capture_decltype (tree decl)
if (!TYPE_REF_P (type))
{
- if (!LAMBDA_EXPR_MUTABLE_P (lam))
- type = cp_build_qualified_type (type, (cp_type_quals (type)
- |TYPE_QUAL_CONST));
+ int quals = cp_type_quals (type);
+ tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
+ gcc_checking_assert (!WILDCARD_TYPE_P (non_reference (obtype)));
+ if (INDIRECT_TYPE_P (obtype))
+ quals |= cp_type_quals (TREE_TYPE (obtype));
+ type = cp_build_qualified_type (type, quals);
type = build_reference_type (type);
}
return type;
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index bf3bcd1bf13..fe47b0a10e6 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -446,8 +446,7 @@ DEFTREECODE (TRAIT_TYPE, "trait_type", tcc_type, 0)
LAMBDA_EXPR_CAPTURE_LIST holds the capture-list, including `this'.
LAMBDA_EXPR_THIS_CAPTURE goes straight to the capture of `this', if it exists.
LAMBDA_EXPR_PENDING_PROXIES is a vector of capture proxies which need to
- be pushed once scope returns to the lambda.
- LAMBDA_EXPR_MUTABLE_P signals whether this lambda was declared mutable. */
+ be pushed once scope returns to the lambda. */
DEFTREECODE (LAMBDA_EXPR, "lambda_expr", tcc_exceptional, 0)
/* The declared type of an expression. This is a C++0x extension.
base-commit: fc7b70fa3497664a58b3c0b36fa94f9ec87d4f22
--
2.39.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] c++: lambda capture and explicit object parm
2023-11-30 5:00 [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P Jason Merrill
@ 2023-12-01 3:50 ` Jason Merrill
2023-12-01 19:03 ` [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P Patrick Palka
1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2023-12-01 3:50 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
More adjustments to allow for explicit object parameters in lambdas. This
has no practical effect until that patch goes in, but applying this
separately seems reasonable.
gcc/cp/ChangeLog:
* semantics.cc (finish_non_static_data_member)
(finish_decltype_type, capture_decltype):
Handle deduced closure parameter.
---
gcc/cp/semantics.cc | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 36b57ac9524..fbbc18336a0 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -2262,6 +2262,16 @@ finish_non_static_data_member (tree decl, tree object, tree qualifying_scope,
else if (PACK_EXPANSION_P (type))
/* Don't bother trying to represent this. */
type = NULL_TREE;
+ else if (WILDCARD_TYPE_P (TREE_TYPE (object)))
+ /* We don't know what the eventual quals will be, so punt until
+ instantiation time.
+
+ This can happen when called from build_capture_proxy for an explicit
+ object lambda. It's a bit marginal to call this function in that
+ case, since this function is for references to members of 'this',
+ but the deduced type is required to be derived from the closure
+ type, so it works. */
+ type = NULL_TREE;
else
{
/* Set the cv qualifiers. */
@@ -11682,6 +11692,7 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
A<decltype(sizeof(T))>::U doesn't require 'typename'. */
if (instantiation_dependent_uneval_expression_p (expr))
{
+ dependent:
type = cxx_make_type (DECLTYPE_TYPE);
DECLTYPE_TYPE_EXPR (type) = expr;
DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
@@ -11856,7 +11867,11 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
if (outer_automatic_var_p (STRIP_REFERENCE_REF (expr))
&& current_function_decl
&& LAMBDA_FUNCTION_P (current_function_decl))
- type = capture_decltype (STRIP_REFERENCE_REF (expr));
+ {
+ type = capture_decltype (STRIP_REFERENCE_REF (expr));
+ if (!type)
+ goto dependent;
+ }
else if (error_operand_p (expr))
type = error_mark_node;
else if (expr == current_class_ptr)
@@ -12754,7 +12769,8 @@ apply_deduced_return_type (tree fco, tree return_type)
/* DECL is a local variable or parameter from the surrounding scope of a
lambda-expression. Returns the decltype for a use of the capture field
- for DECL even if it hasn't been captured yet. */
+ for DECL even if it hasn't been captured yet. Or NULL_TREE if we can't give
+ a correct answer at this point and we should build a DECLTYPE_TYPE. */
static tree
capture_decltype (tree decl)
@@ -12792,9 +12808,11 @@ capture_decltype (tree decl)
if (!TYPE_REF_P (type))
{
- int quals = cp_type_quals (type);
tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
- gcc_checking_assert (!WILDCARD_TYPE_P (non_reference (obtype)));
+ if (WILDCARD_TYPE_P (non_reference (obtype)))
+ /* We don't know what the eventual obtype quals will be. */
+ return NULL_TREE;
+ int quals = cp_type_quals (type);
if (INDIRECT_TYPE_P (obtype))
quals |= cp_type_quals (TREE_TYPE (obtype));
type = cp_build_qualified_type (type, quals);
base-commit: f2c52c0dfde581461959b0e2b423ad106aadf179
--
2.39.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P
2023-11-30 5:00 [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P Jason Merrill
2023-12-01 3:50 ` [PATCH] c++: lambda capture and explicit object parm Jason Merrill
@ 2023-12-01 19:03 ` Patrick Palka
1 sibling, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2023-12-01 19:03 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches, waffl3x
On Thu, 30 Nov 2023, Jason Merrill wrote:
> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> -- 8< --
>
> In review of the deducing 'this' patch it came up that LAMBDA_EXPR_MUTABLE_P
> doesn't make sense for a lambda with an explicit object parameter. And it
> was never necessary, so let's remove it.
>
> gcc/cp/ChangeLog:
>
> * cp-tree.h (LAMBDA_EXPR_MUTABLE_P): Remove.
> * cp-tree.def: Remove documentation.
> * lambda.cc (build_lambda_expr): Remove reference.
> * parser.cc (cp_parser_lambda_declarator_opt): Likewise.
> * pt.cc (tsubst_lambda_expr): Likewise.
> * ptree.cc (cxx_print_lambda_node): Likewise.
> * semantics.cc (capture_decltype): Get the object quals
> from the object instead.
> ---
> gcc/cp/cp-tree.h | 5 -----
> gcc/cp/lambda.cc | 1 -
> gcc/cp/parser.cc | 1 -
> gcc/cp/pt.cc | 1 -
> gcc/cp/ptree.cc | 2 --
> gcc/cp/semantics.cc | 9 ++++++---
> gcc/cp/cp-tree.def | 3 +--
> 7 files changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 5614b71eed4..964af1ddd85 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -461,7 +461,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
> TYPENAME_IS_CLASS_P (in TYPENAME_TYPE)
> STMT_IS_FULL_EXPR_P (in _STMT)
> TARGET_EXPR_LIST_INIT_P (in TARGET_EXPR)
> - LAMBDA_EXPR_MUTABLE_P (in LAMBDA_EXPR)
> DECL_FINAL_P (in FUNCTION_DECL)
> QUALIFIED_NAME_IS_TEMPLATE (in SCOPE_REF)
> CONSTRUCTOR_IS_DEPENDENT (in CONSTRUCTOR)
> @@ -1478,10 +1477,6 @@ enum cp_lambda_default_capture_mode_type {
> #define LAMBDA_EXPR_CAPTURES_THIS_P(NODE) \
> LAMBDA_EXPR_THIS_CAPTURE(NODE)
>
> -/* Predicate tracking whether the lambda was declared 'mutable'. */
> -#define LAMBDA_EXPR_MUTABLE_P(NODE) \
> - TREE_LANG_FLAG_1 (LAMBDA_EXPR_CHECK (NODE))
> -
> /* True iff uses of a const variable capture were optimized away. */
> #define LAMBDA_EXPR_CAPTURE_OPTIMIZED(NODE) \
> TREE_LANG_FLAG_2 (LAMBDA_EXPR_CHECK (NODE))
> diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
> index 34d0190a89b..be8d240944d 100644
> --- a/gcc/cp/lambda.cc
> +++ b/gcc/cp/lambda.cc
> @@ -44,7 +44,6 @@ build_lambda_expr (void)
> LAMBDA_EXPR_THIS_CAPTURE (lambda) = NULL_TREE;
> LAMBDA_EXPR_REGEN_INFO (lambda) = NULL_TREE;
> LAMBDA_EXPR_PENDING_PROXIES (lambda) = NULL;
> - LAMBDA_EXPR_MUTABLE_P (lambda) = false;
> return lambda;
> }
>
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 2464d1a0783..1826b6175f5 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -11770,7 +11770,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr)
>
> if (lambda_specs.storage_class == sc_mutable)
> {
> - LAMBDA_EXPR_MUTABLE_P (lambda_expr) = 1;
> quals = TYPE_UNQUALIFIED;
> }
> else if (lambda_specs.storage_class == sc_static)
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index c18718b319d..00a808bf323 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -19341,7 +19341,6 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
> = LAMBDA_EXPR_LOCATION (t);
> LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (r)
> = LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (t);
> - LAMBDA_EXPR_MUTABLE_P (r) = LAMBDA_EXPR_MUTABLE_P (t);
> if (tree ti = LAMBDA_EXPR_REGEN_INFO (t))
> LAMBDA_EXPR_REGEN_INFO (r)
> = build_template_info (t, add_to_template_args (TI_ARGS (ti),
> diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc
> index 32c5b5280dc..d1f58921fab 100644
> --- a/gcc/cp/ptree.cc
> +++ b/gcc/cp/ptree.cc
> @@ -265,8 +265,6 @@ cxx_print_identifier (FILE *file, tree node, int indent)
> void
> cxx_print_lambda_node (FILE *file, tree node, int indent)
> {
> - if (LAMBDA_EXPR_MUTABLE_P (node))
> - fprintf (file, " /mutable");
> fprintf (file, " default_capture_mode=[");
> switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (node))
> {
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 04b0540599a..36b57ac9524 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12792,9 +12792,12 @@ capture_decltype (tree decl)
>
> if (!TYPE_REF_P (type))
> {
> - if (!LAMBDA_EXPR_MUTABLE_P (lam))
> - type = cp_build_qualified_type (type, (cp_type_quals (type)
> - |TYPE_QUAL_CONST));
> + int quals = cp_type_quals (type);
> + tree obtype = TREE_TYPE (DECL_ARGUMENTS (current_function_decl));
> + gcc_checking_assert (!WILDCARD_TYPE_P (non_reference (obtype)));
> + if (INDIRECT_TYPE_P (obtype))
> + quals |= cp_type_quals (TREE_TYPE (obtype));
Shouldn't we propagate cv-quals of a by-value object parameter as well?
> + type = cp_build_qualified_type (type, quals);
> type = build_reference_type (type);
> }
> return type;
> diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
> index bf3bcd1bf13..fe47b0a10e6 100644
> --- a/gcc/cp/cp-tree.def
> +++ b/gcc/cp/cp-tree.def
> @@ -446,8 +446,7 @@ DEFTREECODE (TRAIT_TYPE, "trait_type", tcc_type, 0)
> LAMBDA_EXPR_CAPTURE_LIST holds the capture-list, including `this'.
> LAMBDA_EXPR_THIS_CAPTURE goes straight to the capture of `this', if it exists.
> LAMBDA_EXPR_PENDING_PROXIES is a vector of capture proxies which need to
> - be pushed once scope returns to the lambda.
> - LAMBDA_EXPR_MUTABLE_P signals whether this lambda was declared mutable. */
> + be pushed once scope returns to the lambda. */
> DEFTREECODE (LAMBDA_EXPR, "lambda_expr", tcc_exceptional, 0)
>
> /* The declared type of an expression. This is a C++0x extension.
>
> base-commit: fc7b70fa3497664a58b3c0b36fa94f9ec87d4f22
> --
> 2.39.3
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-01 19:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 5:00 [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P Jason Merrill
2023-12-01 3:50 ` [PATCH] c++: lambda capture and explicit object parm Jason Merrill
2023-12-01 19:03 ` [pushed] c++: remove LAMBDA_EXPR_MUTABLE_P 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).