summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-04-14 15:34:14 -0400
committerJason Merrill <jason@redhat.com>2022-05-13 13:39:30 -0400
commit7b4bd8dbd8d07e298528b0f033102ce8f693e739 (patch)
treebf52f37661eff4b5cb94fa638aa1dd18d160bc8d
parent3daf541e8fe2dd0807a3dd49a9b8c065d7d46731 (diff)
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.c (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.
-rw-r--r--gcc/cp/constexpr.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-fno-elide-ctors1.C89
2 files changed, 90 insertions, 1 deletions
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index c7468812e31..b886082d128 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -890,7 +890,7 @@ register_constexpr_fundef (tree fun, tree body)
return NULL;
}
- if (DECL_CONSTRUCTOR_P (fun)
+ if (DECL_CONSTRUCTOR_P (fun) && !DECL_DEFAULTED_FN (fun)
&& cx_check_missing_mem_inits (DECL_CONTEXT (fun),
massaged, !DECL_GENERATED_P (fun)))
return NULL;
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 00000000000..71c76fa0247
--- /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 <typename _T1> struct pair {
+ _T1 first;
+ int second;
+};
+template <typename _Iterator> class __normal_iterator {
+ _Iterator __traits_type;
+
+public:
+ constexpr __normal_iterator() {}
+};
+template <typename> class allocator;
+template <typename> struct allocator_traits;
+template <typename _Tp> struct allocator_traits<allocator<_Tp>> {
+ using value_type = _Tp;
+ template <typename _Up> using rebind_alloc = allocator<_Up>;
+};
+template <typename _Alloc> struct __alloc_traits {
+ typedef allocator_traits<_Alloc> _Base_type;
+ typedef typename _Base_type::value_type &const_reference;
+ template <typename _Tp> struct rebind {
+ typedef typename _Base_type::template rebind_alloc<_Tp> other;
+ };
+};
+template <typename _Tp, typename _Alloc> struct _Vector_base {
+ typedef typename __alloc_traits<_Alloc>::template rebind<_Tp>::other _Tp_alloc_type;
+};
+template <typename _Tp, typename _Alloc = allocator<_Tp>> class vector {
+public:
+ typename __alloc_traits<
+ typename _Vector_base<_Tp, _Alloc>::_Tp_alloc_type>::const_reference
+ operator[](long);
+};
+enum match_flag_type {};
+template <typename, typename> class Trans_NS___cxx11_basic_regex;
+class Trans_NS___cxx11_match_results;
+enum _RegexExecutorPolicy { _S_auto };
+template <typename, typename, typename _CharT, typename _TraitsT,
+ _RegexExecutorPolicy, bool>
+bool __regex_algo_impl(Trans_NS___cxx11_match_results &,
+ const Trans_NS___cxx11_basic_regex<_CharT, _TraitsT> &);
+template <typename, typename, typename, bool> class _Executor;
+template <typename _Ch_type, typename = _Ch_type>
+class Trans_NS___cxx11_basic_regex {};
+class Trans_NS___cxx11_match_results : vector<int> {
+ template <typename, typename, typename _Cp, typename _Rp,
+ _RegexExecutorPolicy, bool>
+ friend bool __regex_algo_impl(Trans_NS___cxx11_match_results &,
+ const Trans_NS___cxx11_basic_regex<_Cp, _Rp> &);
+};
+template <typename _Bi_iter, typename _Alloc, typename _Ch_type,
+ typename _Rx_traits>
+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 <typename, typename, typename _CharT, typename _TraitsT,
+ _RegexExecutorPolicy, bool>
+bool __regex_algo_impl(
+ Trans_NS___cxx11_match_results &__m,
+ const Trans_NS___cxx11_basic_regex<_CharT, _TraitsT> &__re) {
+ __normal_iterator<const char *> __e, __s;
+ _Executor<int, int, _TraitsT, false> __executor(__s, __e, __m, __re,
+ __regex_algo_impl___flags);
+ __executor._M_match();
+ return false;
+}
+template <typename, typename, typename, bool> class _Executor {
+public:
+ _Executor(__normal_iterator<const char *>, __normal_iterator<const char *>,
+ vector<int>, Trans_NS___cxx11_basic_regex<char>, match_flag_type);
+ void _M_match() { _M_dfs(); }
+ void _M_dfs();
+ vector<pair<__normal_iterator<char *>>> _M_rep_count;
+};
+long _M_rep_once_more___i;
+template <typename _BiIter, typename _Alloc, typename _TraitsT, bool __dfs_mode>
+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<char> re;
+ regex_search(main___trans_tmp_1, main___trans_tmp_2, re);
+}