c++: deleted fn and noexcept inst [PR101532, PR104225]
Here when attempting to use B's implicitly deleted default constructor, mark_used rightfully returns false, but for the wrong reason: it tries to instantiate the synthesized noexcept specifier which then only silently fails because get_defaulted_eh_spec suppresses diagnostics for deleted functions. This lack of diagnostics causes us to crash on the first testcase below (thanks to the assert in finish_expr_stmt), and silently accept the second testcase. To fix this, this patch makes mark_used avoid attempting to instantiate the noexcept specifier of a deleted function, so that we'll instead directly reject (and diagnose) the function due to its deletedness. PR c++/101532 PR c++/104225 gcc/cp/ChangeLog: * decl2.cc (mark_used): Don't consider maybe_instantiate_noexcept on a deleted function. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/nsdmi-template21.C: New test. * g++.dg/cpp0x/nsdmi-template21a.C: New test.
This commit is contained in:
parent
fe5cee6f62
commit
bc90dd0ecf
@ -5774,6 +5774,7 @@ mark_used (tree decl, tsubst_flags_t complain)
|
||||
used_types_insert (DECL_CONTEXT (decl));
|
||||
|
||||
if (TREE_CODE (decl) == FUNCTION_DECL
|
||||
&& !DECL_DELETED_FN (decl)
|
||||
&& !maybe_instantiate_noexcept (decl, complain))
|
||||
return false;
|
||||
|
||||
|
8
gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C
Normal file
8
gcc/testsuite/g++.dg/cpp0x/nsdmi-template21.C
Normal file
@ -0,0 +1,8 @@
|
||||
// PR c++/101532
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
struct A { private: ~A(); };
|
||||
|
||||
template<class> struct B { A a = A(); }; // { dg-error "private" }
|
||||
|
||||
B<int> b; // { dg-error "deleted" }
|
10
gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C
Normal file
10
gcc/testsuite/g++.dg/cpp0x/nsdmi-template21a.C
Normal file
@ -0,0 +1,10 @@
|
||||
// PR c++/104225
|
||||
// { dg-do compile { target c++11 } }
|
||||
|
||||
struct A { private: ~A(); };
|
||||
|
||||
template<class> struct B { A a = A(); }; // { dg-error "private" }
|
||||
|
||||
int main() {
|
||||
new B<int>; // { dg-error "deleted" }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user