Message ID | 20180122230654.GN2063@tucnak |
---|---|
State | New |
Headers | show |
Series | [C++] Fix a structured binding ICE (PR c++/83958) | expand |
On 01/22/2018 06:06 PM, Jakub Jelinek wrote: > Hi! > > I've recently added the complete_type call in case the structured binding > is a reference to a type that needs to be instantiated. > This testcase shows a problem where it can't be instantiated and we ICE > because we don't expect an incomplete type. If decl isn't a reference, > cp_finish_decl for it should handle everything. > I've considered using complete_type_or_else, but we aren't checking that > decl's type is complete, but rather that the type it refers to is complete, > and furthermore not sure if it is very nice to print <structured bindings> > in the diagnostics. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2018-01-22 Jakub Jelinek <jakub@redhat.com> > > PR c++/83958 > * decl.c (cp_finish_decomp): Diagnose if reference structure binding > refers to incomplete type. > > * g++.dg/cpp1z/decomp35.C: New test. ok, thanks
--- gcc/cp/decl.c.jj 2018-01-19 23:34:36.634278658 +0100 +++ gcc/cp/decl.c 2018-01-22 12:16:39.316524652 +0100 @@ -7433,6 +7433,12 @@ cp_finish_decomp (tree decl, tree first, type = complete_type (TREE_TYPE (type)); if (type == error_mark_node) goto error_out; + if (!COMPLETE_TYPE_P (type)) + { + error_at (loc, "structured binding refers to incomplete type %qT", + type); + goto error_out; + } } tree eltype = NULL_TREE; --- gcc/testsuite/g++.dg/cpp1z/decomp35.C.jj 2018-01-22 12:18:19.421399364 +0100 +++ gcc/testsuite/g++.dg/cpp1z/decomp35.C 2018-01-22 12:22:28.243046089 +0100 @@ -0,0 +1,35 @@ +// PR c++/83958 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template <typename = void> struct A; +class B; +template <typename, typename, typename = A<>> class C; +template <typename, typename> struct D; +template <typename T, typename U, typename V, typename, typename, typename W> +struct E { + using X = W; + X operator* (); + T operator++ (); + template <typename P, typename R, typename S, typename Q> + bool operator!= (E<P, U, V, R, S, Q>); +}; +template <typename T, typename U, typename> +struct F { + class G; + using H = D<T, U>; + using I = E<G, T, U, G, H, H &>; + class G : public I {}; + G begin (); + G end (); +}; +template <typename T, typename U, typename V> struct C : F<T, U, V> { + using J = F<T, U, V>; + using J::begin; + using J::end; +}; +using K = class L; +struct M { + void foo () { for (auto & [ a ] : m) {} } // { dg-error "incomplete type" } + C<K, B> m; // { dg-warning "only available with" "" { target c++14_down } .-1 } +};