Lines 1099-1105
maybe_add_lambda_conv_op (tree type)
Link Here
|
1099 |
tree optype = TREE_TYPE (callop); |
1099 |
tree optype = TREE_TYPE (callop); |
1100 |
tree fn_result = TREE_TYPE (optype); |
1100 |
tree fn_result = TREE_TYPE (optype); |
1101 |
|
1101 |
|
1102 |
tree thisarg = build_int_cst (TREE_TYPE (DECL_ARGUMENTS (callop)), 0); |
1102 |
tree thisarg = NULL_TREE; |
|
|
1103 |
if (TREE_CODE (optype) == METHOD_TYPE) |
1104 |
thisarg = build_int_cst (TREE_TYPE (DECL_ARGUMENTS (callop)), 0); |
1103 |
if (generic_lambda_p) |
1105 |
if (generic_lambda_p) |
1104 |
{ |
1106 |
{ |
1105 |
++processing_template_decl; |
1107 |
++processing_template_decl; |
Lines 1109-1126
maybe_add_lambda_conv_op (tree type)
Link Here
|
1109 |
return expression for a deduced return call op to allow for simple |
1111 |
return expression for a deduced return call op to allow for simple |
1110 |
implementation of the conversion operator. */ |
1112 |
implementation of the conversion operator. */ |
1111 |
|
1113 |
|
1112 |
tree instance = cp_build_fold_indirect_ref (thisarg); |
|
|
1113 |
tree objfn = lookup_template_function (DECL_NAME (callop), |
1114 |
tree objfn = lookup_template_function (DECL_NAME (callop), |
1114 |
DECL_TI_ARGS (callop)); |
1115 |
DECL_TI_ARGS (callop)); |
1115 |
objfn = build_min (COMPONENT_REF, NULL_TREE, |
1116 |
int nargs = list_length (DECL_ARGUMENTS (callop)); |
1116 |
instance, objfn, NULL_TREE); |
1117 |
if (thisarg) |
1117 |
int nargs = list_length (DECL_ARGUMENTS (callop)) - 1; |
1118 |
{ |
|
|
1119 |
tree instance = cp_build_fold_indirect_ref (thisarg); |
1120 |
objfn = build_min (COMPONENT_REF, NULL_TREE, |
1121 |
instance, objfn, NULL_TREE); |
1122 |
--nargs; |
1123 |
call = prepare_op_call (objfn, nargs); |
1124 |
} |
1118 |
|
1125 |
|
1119 |
call = prepare_op_call (objfn, nargs); |
|
|
1120 |
if (type_uses_auto (fn_result)) |
1126 |
if (type_uses_auto (fn_result)) |
1121 |
decltype_call = prepare_op_call (objfn, nargs); |
1127 |
decltype_call = prepare_op_call (objfn, nargs); |
1122 |
} |
1128 |
} |
1123 |
else |
1129 |
else if (thisarg) |
1124 |
{ |
1130 |
{ |
1125 |
direct_argvec = make_tree_vector (); |
1131 |
direct_argvec = make_tree_vector (); |
1126 |
direct_argvec->quick_push (thisarg); |
1132 |
direct_argvec->quick_push (thisarg); |
Lines 1135-1143
maybe_add_lambda_conv_op (tree type)
Link Here
|
1135 |
tree fn_args = NULL_TREE; |
1141 |
tree fn_args = NULL_TREE; |
1136 |
{ |
1142 |
{ |
1137 |
int ix = 0; |
1143 |
int ix = 0; |
1138 |
tree src = DECL_CHAIN (DECL_ARGUMENTS (callop)); |
1144 |
tree src = DECL_ARGUMENTS (callop); |
1139 |
tree tgt = NULL; |
1145 |
tree tgt = NULL; |
1140 |
|
1146 |
|
|
|
1147 |
if (thisarg) |
1148 |
src = DECL_CHAIN (src); |
1149 |
else if (!decltype_call) |
1150 |
src = NULL_TREE; |
1141 |
while (src) |
1151 |
while (src) |
1142 |
{ |
1152 |
{ |
1143 |
tree new_node = copy_node (src); |
1153 |
tree new_node = copy_node (src); |
Lines 1160-1171
maybe_add_lambda_conv_op (tree type)
Link Here
|
1160 |
if (generic_lambda_p) |
1170 |
if (generic_lambda_p) |
1161 |
{ |
1171 |
{ |
1162 |
tree a = tgt; |
1172 |
tree a = tgt; |
1163 |
if (DECL_PACK_P (tgt)) |
1173 |
if (thisarg) |
1164 |
{ |
1174 |
{ |
1165 |
a = make_pack_expansion (a); |
1175 |
if (DECL_PACK_P (tgt)) |
1166 |
PACK_EXPANSION_LOCAL_P (a) = true; |
1176 |
{ |
|
|
1177 |
a = make_pack_expansion (a); |
1178 |
PACK_EXPANSION_LOCAL_P (a) = true; |
1179 |
} |
1180 |
CALL_EXPR_ARG (call, ix) = a; |
1167 |
} |
1181 |
} |
1168 |
CALL_EXPR_ARG (call, ix) = a; |
|
|
1169 |
|
1182 |
|
1170 |
if (decltype_call) |
1183 |
if (decltype_call) |
1171 |
{ |
1184 |
{ |
Lines 1193-1199
maybe_add_lambda_conv_op (tree type)
Link Here
|
1193 |
tf_warning_or_error); |
1206 |
tf_warning_or_error); |
1194 |
} |
1207 |
} |
1195 |
} |
1208 |
} |
1196 |
else |
1209 |
else if (thisarg) |
1197 |
{ |
1210 |
{ |
1198 |
/* Don't warn on deprecated or unavailable lambda declarations, unless |
1211 |
/* Don't warn on deprecated or unavailable lambda declarations, unless |
1199 |
the lambda is actually called. */ |
1212 |
the lambda is actually called. */ |
Lines 1203-1216
maybe_add_lambda_conv_op (tree type)
Link Here
|
1203 |
direct_argvec->address ()); |
1216 |
direct_argvec->address ()); |
1204 |
} |
1217 |
} |
1205 |
|
1218 |
|
1206 |
CALL_FROM_THUNK_P (call) = 1; |
1219 |
if (thisarg) |
1207 |
SET_EXPR_LOCATION (call, UNKNOWN_LOCATION); |
1220 |
{ |
|
|
1221 |
CALL_FROM_THUNK_P (call) = 1; |
1222 |
SET_EXPR_LOCATION (call, UNKNOWN_LOCATION); |
1223 |
} |
1208 |
|
1224 |
|
1209 |
tree stattype = build_function_type (fn_result, FUNCTION_ARG_CHAIN (callop)); |
1225 |
tree stattype |
1210 |
stattype = (cp_build_type_attribute_variant |
1226 |
= build_function_type (fn_result, thisarg ? FUNCTION_ARG_CHAIN (callop) |
1211 |
(stattype, TYPE_ATTRIBUTES (optype))); |
1227 |
: TYPE_ARG_TYPES (optype)); |
1212 |
if (flag_noexcept_type |
1228 |
stattype = cp_build_type_attribute_variant (stattype, |
1213 |
&& TYPE_NOTHROW_P (TREE_TYPE (callop))) |
1229 |
TYPE_ATTRIBUTES (optype)); |
|
|
1230 |
if (flag_noexcept_type && TYPE_NOTHROW_P (TREE_TYPE (callop))) |
1214 |
stattype = build_exception_variant (stattype, noexcept_true_spec); |
1231 |
stattype = build_exception_variant (stattype, noexcept_true_spec); |
1215 |
|
1232 |
|
1216 |
if (generic_lambda_p) |
1233 |
if (generic_lambda_p) |
Lines 1249-1254
maybe_add_lambda_conv_op (tree type)
Link Here
|
1249 |
|
1266 |
|
1250 |
add_method (type, fn, false); |
1267 |
add_method (type, fn, false); |
1251 |
|
1268 |
|
|
|
1269 |
if (thisarg == NULL_TREE) |
1270 |
{ |
1271 |
/* For static lambda, just return operator(). */ |
1272 |
if (nested) |
1273 |
push_function_context (); |
1274 |
else |
1275 |
/* Still increment function_depth so that we don't GC in the |
1276 |
middle of an expression. */ |
1277 |
++function_depth; |
1278 |
|
1279 |
/* Generate the body of the conversion op. */ |
1280 |
|
1281 |
start_preparsed_function (convfn, NULL_TREE, |
1282 |
SF_PRE_PARSED | SF_INCLASS_INLINE); |
1283 |
tree body = begin_function_body (); |
1284 |
tree compound_stmt = begin_compound_stmt (0); |
1285 |
|
1286 |
/* decl_needed_p needs to see that it's used. */ |
1287 |
TREE_USED (callop) = 1; |
1288 |
finish_return_stmt (decay_conversion (callop, tf_warning_or_error)); |
1289 |
|
1290 |
finish_compound_stmt (compound_stmt); |
1291 |
finish_function_body (body); |
1292 |
|
1293 |
fn = finish_function (/*inline_p=*/true); |
1294 |
if (!generic_lambda_p) |
1295 |
expand_or_defer_fn (fn); |
1296 |
|
1297 |
if (nested) |
1298 |
pop_function_context (); |
1299 |
else |
1300 |
--function_depth; |
1301 |
return; |
1302 |
} |
1303 |
|
1252 |
/* Generic thunk code fails for varargs; we'll complain in mark_used if |
1304 |
/* Generic thunk code fails for varargs; we'll complain in mark_used if |
1253 |
the conversion op is used. */ |
1305 |
the conversion op is used. */ |
1254 |
if (varargs_function_p (callop)) |
1306 |
if (varargs_function_p (callop)) |