From c5de3444c4798758cdd800eca144480b4a8ef299 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 14 Apr 2022 15:34:14 -0400 Subject: [PATCH] c++: constexpr trivial -fno-elide-ctors [PR104646] The constexpr constructor checking code got confused by the expansion of a trivial copy constructor; we don't need to do that checking for defaulted ctors, anyway. PR c++/104646 gcc/cp/ChangeLog: * constexpr.cc (maybe_save_constexpr_fundef): Don't do extra checks for defaulted ctors. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-fno-elide-ctors1.C: New test. --- gcc/cp/constexpr.cc | 3 +- .../g++.dg/cpp0x/constexpr-fno-elide-ctors1.C | 89 +++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-fno-elide-ctors1.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index b170053e8e16..e89440e770f6 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -920,7 +920,8 @@ maybe_save_constexpr_fundef (tree fun) if (!potential && complain) require_potential_rvalue_constant_expression (massaged); - if (DECL_CONSTRUCTOR_P (fun) && potential) + if (DECL_CONSTRUCTOR_P (fun) && potential + && !DECL_DEFAULTED_FN (fun)) { if (cx_check_missing_mem_inits (DECL_CONTEXT (fun), massaged, complain)) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-fno-elide-ctors1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-fno-elide-ctors1.C new file mode 100644 index 000000000000..71c76fa02471 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-fno-elide-ctors1.C @@ -0,0 +1,89 @@ +// PR c++/104646 +// { dg-do compile { target c++11 } } +// { dg-additional-options -fno-elide-constructors } + +template struct pair { + _T1 first; + int second; +}; +template class __normal_iterator { + _Iterator __traits_type; + +public: + constexpr __normal_iterator() {} +}; +template class allocator; +template struct allocator_traits; +template struct allocator_traits> { + using value_type = _Tp; + template using rebind_alloc = allocator<_Up>; +}; +template struct __alloc_traits { + typedef allocator_traits<_Alloc> _Base_type; + typedef typename _Base_type::value_type &const_reference; + template struct rebind { + typedef typename _Base_type::template rebind_alloc<_Tp> other; + }; +}; +template struct _Vector_base { + typedef typename __alloc_traits<_Alloc>::template rebind<_Tp>::other _Tp_alloc_type; +}; +template > class vector { +public: + typename __alloc_traits< + typename _Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_reference + operator[](long); +}; +enum match_flag_type {}; +template class Trans_NS___cxx11_basic_regex; +class Trans_NS___cxx11_match_results; +enum _RegexExecutorPolicy { _S_auto }; +template +bool __regex_algo_impl(Trans_NS___cxx11_match_results &, + const Trans_NS___cxx11_basic_regex<_CharT, _TraitsT> &); +template class _Executor; +template +class Trans_NS___cxx11_basic_regex {}; +class Trans_NS___cxx11_match_results : vector { + template + friend bool __regex_algo_impl(Trans_NS___cxx11_match_results &, + const Trans_NS___cxx11_basic_regex<_Cp, _Rp> &); +}; +template +void regex_search(_Bi_iter, _Alloc, + Trans_NS___cxx11_basic_regex<_Ch_type, _Rx_traits>) { + __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, _S_auto, false>; +} +match_flag_type __regex_algo_impl___flags; +template +bool __regex_algo_impl( + Trans_NS___cxx11_match_results &__m, + const Trans_NS___cxx11_basic_regex<_CharT, _TraitsT> &__re) { + __normal_iterator __e, __s; + _Executor __executor(__s, __e, __m, __re, + __regex_algo_impl___flags); + __executor._M_match(); + return false; +} +template class _Executor { +public: + _Executor(__normal_iterator, __normal_iterator, + vector, Trans_NS___cxx11_basic_regex, match_flag_type); + void _M_match() { _M_dfs(); } + void _M_dfs(); + vector>> _M_rep_count; +}; +long _M_rep_once_more___i; +template +void _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>::_M_dfs() { + auto __rep_count = _M_rep_count[_M_rep_once_more___i]; +} +char main___trans_tmp_1; +void main___trans_tmp_2() { + Trans_NS___cxx11_basic_regex re; + regex_search(main___trans_tmp_1, main___trans_tmp_2, re); +} -- 2.47.2