diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 02f3e89b28b..55fd37f649c 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -134,6 +134,14 @@ get_reflection (location_t loc, tree t, reflect_kind kind/*=REFLECT_UNDEF*/) "parameter %qD", t); return error_mark_node; } + /* If the id-expression denotes a variable declared by an init-capture, + R is ill-formed. */ + else if (is_capture_proxy (t)) + { + error_at (loc, "%<^^%> cannot be applied to a local entity declared " + "by init-capture"); + return error_mark_node; + } /* If the id-expression denotes a local parameter introduced by a requires-expression, R is ill-formed. */ else if (TREE_CODE (t) == PARM_DECL && CONSTRAINT_VAR_P (t)) @@ -159,14 +167,6 @@ get_reflection (location_t loc, tree t, reflect_kind kind/*=REFLECT_UNDEF*/) inform (DECL_SOURCE_LOCATION (t), "%qD declared here", t); return error_mark_node; } - /* If the id-expression denotes a variable declared by an init-capture, - R is ill-formed. */ - else if (is_capture_proxy (t) && !is_normal_capture_proxy (t)) - { - error_at (loc, "%<^^%> cannot be applied to a local entity declared " - "by init-capture"); - return error_mark_node; - } /* If lookup finds a declaration that replaced a using-declarator during a single search, R is ill-formed. */ else if (TREE_CODE (t) == USING_DECL diff --git a/gcc/testsuite/g++.dg/reflect/expr6.C b/gcc/testsuite/g++.dg/reflect/expr6.C index bd9624bc084..d7d0574ae88 100644 --- a/gcc/testsuite/g++.dg/reflect/expr6.C +++ b/gcc/testsuite/g++.dg/reflect/expr6.C @@ -43,7 +43,7 @@ h () constexpr auto r3 = ^^y; // { dg-error "intervening lambda expression" } [x_]() { - constexpr auto r4 = ^^x_; // { dg-error "intervening lambda expression" } + constexpr auto r4 = ^^x_; // { dg-error "local entity declared by init-capture" } }; }; }