definition, so don't try to look at the closure. But if the
captured variable is constant, try to evaluate it directly. */
r = DECL_CAPTURED_VARIABLE (t);
- tree type = TREE_TYPE (t);
- if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
- {
- /* Adjust r to match the reference-ness of t. */
- if (TYPE_REF_P (type))
- r = build_address (r);
- else
- r = convert_from_reference (r);
- }
}
else
r = DECL_VALUE_EXPR (t);
+
+ tree type = TREE_TYPE (t);
+ if (TYPE_REF_P (type) != TYPE_REF_P (TREE_TYPE (r)))
+ {
+ /* Adjust r to match the reference-ness of t. */
+ if (TYPE_REF_P (type))
+ r = build_address (r);
+ else
+ r = convert_from_reference (r);
+ }
return cxx_eval_constant_expression (ctx, r, lval, non_constant_p,
overflow_p);
}
--- /dev/null
+// PR c++/118053
+// { dg-do compile { target c++14 } }
+
+template <typename _Tp> struct vector {
+ _Tp * _M_finish;
+ vector(_Tp);
+ vector(const vector &);
+ constexpr auto back() { return *_M_finish; }
+};
+template <typename Funct> void
+run(Funct funct) { funct(1); }
+
+vector<int>
+runner() try {
+ vector<int> vec{1};
+ run([&](auto) { vec.back(); });
+ return vec;
+} catch (...) {
+ return 1;
+}