extern void insert_pending_capture_proxies (void);
extern bool is_capture_proxy (tree);
extern bool is_normal_capture_proxy (tree);
+extern tree strip_normal_capture_proxy (tree);
extern bool is_constant_capture_proxy (tree);
extern void register_capture_members (tree);
extern tree lambda_expr_this_capture (tree, int);
&& DECL_CAPTURED_VARIABLE (decl));
}
+/* If DECL is a normal capture proxy, return the variable it captures.
+ Otherwise, just return DECL. */
+
+tree
+strip_normal_capture_proxy (tree decl)
+{
+ while (is_normal_capture_proxy (decl))
+ decl = DECL_CAPTURED_VARIABLE (decl);
+ return decl;
+}
+
/* Returns true iff DECL is a capture proxy for a normal capture
of a constant variable. */
STRIP_NOPS (init);
gcc_assert (VAR_P (init) || TREE_CODE (init) == PARM_DECL);
- while (is_normal_capture_proxy (init))
- init = DECL_CAPTURED_VARIABLE (init);
+ init = strip_normal_capture_proxy (init);
retrofit_lang_decl (var);
DECL_CAPTURED_VARIABLE (var) = init;
}
tree lambda_stack = NULL_TREE;
tree lambda_expr = NULL_TREE;
tree initializer = convert_from_reference (decl);
+ tree var = strip_normal_capture_proxy (decl);
/* Mark it as used now even if the use is ill-formed. */
if (!mark_used (decl, complain))
if (containing_function && LAMBDA_FUNCTION_P (containing_function))
{
/* Check whether we've already built a proxy. */
- tree var = decl;
- while (is_normal_capture_proxy (var))
- var = DECL_CAPTURED_VARIABLE (var);
tree d = retrieve_local_specialization (var);
if (d && d != decl && is_capture_proxy (d))
/* Only an odr-use of an outer automatic variable causes an
error, and a constant variable can decay to a prvalue
constant without odr-use. So don't complain yet. */
- else if (!odr_use && decl_constant_var_p (decl))
- return decl;
+ else if (!odr_use && decl_constant_var_p (var))
+ return var;
else if (lambda_expr)
{
if (complain & tf_error)
--- /dev/null
+// PR c++/110584
+// { dg-do "run" { target c++11 } }
+
+void foo (int i) {
+ if (i != 0)
+ __builtin_abort ();
+}
+
+int main () {
+ const int x = 0;
+
+ // We would error out on this.
+ (void) [&] () {
+ foo (x);
+ (void) [] () {
+ foo (x);
+ };
+ } ();
+ // As well as those.
+ (void) [&] () {
+ (void) [] () {
+ foo (x);
+ };
+ } ();
+ (void) [&x] () {
+ (void) [] () {
+ foo (x);
+ };
+ } ();
+ // But those would work already.
+ (void) [] () {
+ (void) [&] () {
+ foo (x);
+ };
+ } ();
+ (void) [&] () {
+ (void) [&] () {
+ foo (x);
+ };
+ } ();
+ (void) [=] () {
+ (void) [] () {
+ foo (x);
+ };
+ } ();
+}