diff options
author | Jason Merrill <jason@redhat.com> | 2017-09-28 15:39:45 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-09-28 15:39:45 -0400 |
commit | 281e6c1d8f1b4ca552d8ce2276ddecfcd6ffb15e (patch) | |
tree | 4ec4cc5dfce6282bcbc8d1adfbbb092073395b53 /gcc/cp/semantics.c | |
parent | 5c263e84ab7e5df28a9055ae533c2d305f4b7b3d (diff) | |
download | gcc-281e6c1d8f1b4ca552d8ce2276ddecfcd6ffb15e.zip gcc-281e6c1d8f1b4ca552d8ce2276ddecfcd6ffb15e.tar.gz gcc-281e6c1d8f1b4ca552d8ce2276ddecfcd6ffb15e.tar.bz2 |
PR c++/56973, DR 696 - capture constant variables only as needed.
* expr.c (mark_use): Split out from mark_rvalue_use and
mark_lvalue_use. Handle lambda capture of constant variables.
(mark_lvalue_use_nonread): New.
* semantics.c (process_outer_var_ref): Don't capture a constant
variable until forced.
* pt.c (processing_nonlambda_template): New.
* call.c (build_this): Check it.
* decl2.c (grok_array_decl): Call mark_rvalue_use and
mark_lvalue_use_nonread.
* init.c (constant_value_1): Don't call mark_rvalue_use.
* typeck.c (build_static_cast): Handle lambda capture.
From-SVN: r253266
Diffstat (limited to 'gcc/cp/semantics.c')
-rw-r--r-- | gcc/cp/semantics.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 4e87e47..d96423f 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3282,7 +3282,7 @@ outer_automatic_var_p (tree decl) rewrite it for lambda capture. */ tree -process_outer_var_ref (tree decl, tsubst_flags_t complain) +process_outer_var_ref (tree decl, tsubst_flags_t complain, bool force_use) { if (cp_unevaluated_operand) /* It's not a use (3.2) if we're in an unevaluated context. */ @@ -3303,6 +3303,12 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain) if (parsing_nsdmi ()) containing_function = NULL_TREE; + /* Core issue 696: Only an odr-use of an outer automatic variable causes a + capture (or error), and a constant variable can decay to a prvalue + constant without odr-use. So don't capture yet. */ + if (decl_constant_var_p (decl) && !force_use) + return decl; + if (containing_function && LAMBDA_FUNCTION_P (containing_function)) { /* Check whether we've already built a proxy. */ @@ -3314,7 +3320,7 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain) return d; else /* We need to capture an outer proxy. */ - return process_outer_var_ref (d, complain); + return process_outer_var_ref (d, complain, force_use); } } @@ -3353,20 +3359,6 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain) && uses_template_parms (DECL_TI_ARGS (containing_function))) return decl; - /* Core issue 696: "[At the July 2009 meeting] the CWG expressed - support for an approach in which a reference to a local - [constant] automatic variable in a nested class or lambda body - would enter the expression as an rvalue, which would reduce - the complexity of the problem" - - FIXME update for final resolution of core issue 696. */ - if (decl_constant_var_p (decl)) - { - tree t = maybe_constant_value (convert_from_reference (decl)); - if (TREE_CONSTANT (t)) - return t; - } - if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)) { |