From f25d7e06e2327990e34b317761d4bfc92f523bcf Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 22 Jan 2018 16:05:20 +0000 Subject: [PATCH] re PR c++/81933 (Invalid "constexpr call flows off the end of the function" error) PR c++/81933 * typeck2.c (split_nonconstant_init_1): Return false if we didn't split out anything. * g++.dg/cpp1y/constexpr-empty4.C: New test. From-SVN: r256951 --- gcc/cp/ChangeLog | 7 ++- gcc/cp/typeck2.c | 5 ++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/g++.dg/cpp1y/constexpr-empty4.C | 51 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-empty4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0652662f6a1..3cbb2a45c94 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,7 +1,12 @@ +2018-01-22 Marek Polacek + + PR c++/81933 + * typeck2.c (split_nonconstant_init_1): Return false if we didn't + split out anything. + 2018-01-22 Ville Voutilainen PR c++/83895 - * decl.c (grokdeclarator): Don't diagnose extra parens on typedefs. diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 8d933257f5f..8cb0e8811d3 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -725,6 +725,11 @@ split_nonconstant_init_1 (tree dest, tree init) /* The rest of the initializer is now a constant. */ TREE_CONSTANT (init) = 1; + + /* We didn't split out anything. */ + if (num_split_elts == 0) + return false; + return complete_p && complete_ctor_at_level_p (TREE_TYPE (init), num_split_elts, inner_type); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3fd258e43d0..e046a97dd35 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-22 Marek Polacek + + PR c++/81933 + * g++.dg/cpp1y/constexpr-empty4.C: New test. + 2018-01-22 Will Schmidt * gcc.target/powerpc/fold-vec-abs-short-fwrap.c: Add xxspltib to diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-empty4.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty4.C new file mode 100644 index 00000000000..059220f8268 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-empty4.C @@ -0,0 +1,51 @@ +// PR c++/81933 +// { dg-do compile { target c++14 } } + +namespace std { +template struct __decay_and_strip { typedef _Tp __type; }; +template struct enable_if { typedef int type; }; +template struct _Head_base { + constexpr _Head_base(_Head) {} +}; +template struct _Tuple_impl; +template +struct _Tuple_impl<_Idx, _Head, _Tail...> : _Tuple_impl<1, _Tail...>, // { dg-warning "direct base" } + _Head_base<_Head> { + typedef _Tuple_impl<1, _Tail...> _Inherited; + typedef _Head_base<_Head> _Base; + constexpr _Tuple_impl(_Head __head, _Tail... __tail) + : _Inherited(__tail...), _Base(__head) {} + _Tuple_impl(const _Tuple_impl &) = default; + _Tuple_impl(_Tuple_impl &&); +}; +template +struct _Tuple_impl<_Idx, _Head> : _Head_base<_Head> { + typedef _Head_base<_Head> _Base; + constexpr _Tuple_impl(_Head __head) : _Base(__head) {} +}; +template struct _TC { + static constexpr bool _NotSameTuple() { return true; } +}; +template class tuple : _Tuple_impl<0, _Elements...> { + typedef _Tuple_impl<0, _Elements...> _Inherited; + +public: + template ::_NotSameTuple()>::type = false> + constexpr tuple(_UElements... __elements) : _Inherited(__elements...) {} + tuple(const tuple &) = default; +}; +template +constexpr tuple::__type...> + make_tuple(_Elements... __args) { + typedef tuple::__type...> __result_type; + return __result_type(__args...); +} +} +struct any_udt {}; +template constexpr auto flatten(Tuples... tuples) { + auto all = std::make_tuple(tuples...); + auto flat(all); + return flat; +} +constexpr auto fail = flatten(any_udt{}, any_udt{}); -- 2.30.2