From patchwork Wed Nov 9 22:23:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 124730 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 01992B6F71 for ; Thu, 10 Nov 2011 09:23:21 +1100 (EST) Received: (qmail 1133 invoked by alias); 9 Nov 2011 22:23:19 -0000 Received: (qmail 1124 invoked by uid 22791); 9 Nov 2011 22:23:18 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Nov 2011 22:23:04 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pA9MN4UA009042 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Nov 2011 17:23:04 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pA9MN3Ro016941 for ; Wed, 9 Nov 2011 17:23:03 -0500 Received: from [0.0.0.0] (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pA9MN2bj027196 for ; Wed, 9 Nov 2011 17:23:02 -0500 Message-ID: <4EBAFD45.2040505@redhat.com> Date: Wed, 09 Nov 2011 17:23:01 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20111001 Thunderbird/7.0.1 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50972 (ice-on-invalid with noexcept) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org In this testcase we weren't watching the return value of push_tinst_level, so we crashed trying to pop the level we didn't push. Tested x86_64-pc-linux-gnu, applying to trunk. commit b7eabaa932f7f309630fc7163e64d61b1aba17c8 Author: Jason Merrill Date: Wed Nov 9 16:39:25 2011 -0500 PR c++/50972 * pt.c (maybe_instantiate_noexcept): Check the return value of push_tinst_level. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 71a98b0..55eba5a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18166,17 +18166,22 @@ maybe_instantiate_noexcept (tree fn) if (TREE_CODE (noex) == DEFERRED_NOEXCEPT) { - push_tinst_level (fn); - push_access_scope (fn); - input_location = DECL_SOURCE_LOCATION (fn); - noex = tsubst_copy_and_build (DEFERRED_NOEXCEPT_PATTERN (noex), - DEFERRED_NOEXCEPT_ARGS (noex), - tf_warning_or_error, fn, /*function_p=*/false, - /*integral_constant_expression_p=*/true); - pop_access_scope (fn); - pop_tinst_level (); - spec = build_noexcept_spec (noex, tf_warning_or_error); - if (spec == error_mark_node) + if (push_tinst_level (fn)) + { + push_access_scope (fn); + input_location = DECL_SOURCE_LOCATION (fn); + noex = tsubst_copy_and_build (DEFERRED_NOEXCEPT_PATTERN (noex), + DEFERRED_NOEXCEPT_ARGS (noex), + tf_warning_or_error, fn, + /*function_p=*/false, + /*integral_constant_expression_p=*/true); + pop_access_scope (fn); + pop_tinst_level (); + spec = build_noexcept_spec (noex, tf_warning_or_error); + if (spec == error_mark_node) + spec = noexcept_false_spec; + } + else spec = noexcept_false_spec; } else diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept16.C b/gcc/testsuite/g++.dg/cpp0x/noexcept16.C new file mode 100644 index 0000000..10e0be9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept16.C @@ -0,0 +1,130 @@ +// PR c++/50972 +// { dg-do compile { target c++11 } } +// Ignore all errors, we're just testing that this doesn't ICE +// { dg-prune-output "error" } + +namespace std +typedef long unsigned int size_t; +template +struct __and_; +template +struct is_nothrow_move_constructible +{ +}; +template +struct is_nothrow_move_assignable +struct __add_rvalue_reference_helper<_Tp, true> +{ typedef _Tp&& type; }; +template +struct add_rvalue_reference + : public __add_rvalue_reference_helper<_Tp> +{ +}; +template +inline typename add_rvalue_reference<_Tp>::type +declval() noexcept +{ +} +} +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) +template +class new_allocator +{ +}; +} +namespace std __attribute__ ((__visibility__ ("default"))) +class allocator: public __gnu_cxx::new_allocator<_Tp> +{ + template + struct rebind + { typedef allocator<_Tp1> other; }; +}; +} +namespace std __attribute__ ((__visibility__ ("default"))) +template +struct __alloctr_rebind<_Alloc, _Tp, true> +{ + typedef typename _Alloc::template rebind<_Tp>::other __type; +}; +template +struct allocator_traits +{ + template + struct __rebind_alloc + { + typedef typename __alloctr_rebind<_Alloc, _Tp>::__type __type; + }; +} + } +namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) +template +struct __alloc_traits +{ + typedef std::allocator_traits<_Alloc> _Base_type; + static constexpr bool _S_nothrow_swap() + { + return !_S_propagate_on_swap() + || noexcept(swap(std::declval<_Alloc&>(), std::declval<_Alloc&>())); + } + template + struct rebind + { typedef typename _Base_type::template __rebind_alloc<_Tp>::__type other; }; +}; +} +namespace std __attribute__ ((__visibility__ ("default"))) +template +struct _Vector_base +{ + typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template + rebind<_Tp>::other _Tp_alloc_type; +}; +template > +class vector : protected _Vector_base<_Tp, _Alloc> +{ + typedef _Vector_base<_Tp, _Alloc> _Base; + typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; + typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits; + swap(vector& __x) + noexcept(_Alloc_traits::_S_nothrow_swap()); +}; +} +namespace lexertl +namespace detail +} +namespace detail +template +struct basic_internals +{ + typedef std::vector id_type_vector; +}; +}; +template +class basic_state_machine +{ + typedef detail::basic_internals internals; + void minimise () + { + minimise_dfa (dfa_alphabet_, *dfa_, size_); + } + typedef typename internals::id_type_vector id_type_vector; + void minimise_dfa (const id_type dfa_alphabet_, + id_type_vector &dfa_, std::size_t size_) + { + id_type_vector new_dfa_ (front_, front_ + dfa_alphabet_); + dfa_.swap (new_dfa_); + } +} + } +namespace std __attribute__ ((__visibility__ ("default"))) +template +void +swap(_Tp&, _Tp&) + noexcept(__and_, + is_nothrow_move_assignable<_Tp>>::value) + ; +typedef lexertl::basic_state_machine lexstate; +lexstate m_state_machine; +GenerateLexer() +{ + m_state_machine.minimise(); +}