c++: SFINAE for invalid delete-expression [PR79706]
This fixes SFINAE when substitution yields an invalid delete-expression due to the pertinent deallocation function being marked deleted or otherwise inaccessible. We need to check for an erroneous result from build_op_delete_call and exit early in that case, so that we don't build a COND_EXPR around the erroneous result which finish_decltype_type would then quietly accept. gcc/cp/ChangeLog: PR c++/79706 * init.c (build_vec_delete_1): Just return error_mark_node if deallocate_expr is error_mark_node. (build_delete): Just return error_mark_node if do_delete is error_mark_node. gcc/testsuite/ChangeLog: PR c++/79706 * g++.dg/template/sfinae30.C: New test.
This commit is contained in:
parent
7e52f8b1e0
commit
4924293a62
@ -1,3 +1,11 @@
|
||||
2020-05-13 Patrick Palka <ppalka@redhat.com>
|
||||
|
||||
PR c++/79706
|
||||
* init.c (build_vec_delete_1): Just return error_mark_node if
|
||||
deallocate_expr is error_mark_node.
|
||||
(build_delete): Just return error_mark_node if do_delete is
|
||||
error_mark_node.
|
||||
|
||||
2020-05-13 Patrick Palka <ppalka@redhat.com>
|
||||
|
||||
PR c++/95020
|
||||
|
@ -4076,7 +4076,9 @@ build_vec_delete_1 (location_t loc, tree base, tree maxindex, tree type,
|
||||
}
|
||||
|
||||
body = loop;
|
||||
if (!deallocate_expr)
|
||||
if (deallocate_expr == error_mark_node)
|
||||
return error_mark_node;
|
||||
else if (!deallocate_expr)
|
||||
;
|
||||
else if (!body)
|
||||
body = deallocate_expr;
|
||||
@ -4993,7 +4995,9 @@ build_delete (location_t loc, tree otype, tree addr,
|
||||
return expr;
|
||||
}
|
||||
|
||||
if (do_delete)
|
||||
if (do_delete == error_mark_node)
|
||||
return error_mark_node;
|
||||
else if (do_delete)
|
||||
{
|
||||
tree do_delete_call_expr = extract_call_expr (do_delete);
|
||||
if (TREE_CODE (do_delete_call_expr) == CALL_EXPR)
|
||||
|
@ -1,3 +1,8 @@
|
||||
2020-05-13 Patrick Palka <ppalka@redhat.com>
|
||||
|
||||
PR c++/79706
|
||||
* g++.dg/template/sfinae30.C: New test.
|
||||
|
||||
2020-05-13 Patrick Palka <ppalka@redhat.com>
|
||||
|
||||
PR c++/95020
|
||||
|
21
gcc/testsuite/g++.dg/template/sfinae30.C
Normal file
21
gcc/testsuite/g++.dg/template/sfinae30.C
Normal file
@ -0,0 +1,21 @@
|
||||
// PR c++/79706
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
struct A {
|
||||
void operator delete(void*) = delete;
|
||||
private:
|
||||
void operator delete[](void*);
|
||||
};
|
||||
|
||||
extern A *p;
|
||||
|
||||
template<typename T>
|
||||
auto foo(T *t) -> decltype(delete t); // { dg-error "use of deleted function" }
|
||||
|
||||
template<typename T>
|
||||
auto bar(T *t) -> decltype(delete[] t); // { dg-error "private within this context" }
|
||||
|
||||
void baz() {
|
||||
foo<A>(p); // { dg-error "no match" }
|
||||
bar<A>(p); // { dg-error "no match" }
|
||||
}
|
Loading…
Reference in New Issue
Block a user