From: Jonathan Wakely Date: Fri, 12 May 2017 14:43:11 +0000 (+0100) Subject: PR libstdc++/78939 make tuple_size depend on tuple_size X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f859f912e4df1a6dad3ab6f61e8b8ce0dd77e16d;p=gcc.git PR libstdc++/78939 make tuple_size depend on tuple_size PR libstdc++/78939 * include/std/utility (tuple_size): Only define partial specializations when tuple_size::value is valid. * testsuite/20_util/tuple/78939.cc: New. * testsuite/20_util/tuple/cv_tuple_size_neg.cc: New. From-SVN: r247973 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 1aea9ca01c8..afe7a548bf6 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2017-05-12 Jonathan Wakely + + PR libstdc++/78939 + * include/std/utility (tuple_size): Only define partial + specializations when tuple_size::value is valid. + * testsuite/20_util/tuple/78939.cc: New. + * testsuite/20_util/tuple/cv_tuple_size_neg.cc: New. + 2017-05-11 François Dumont * include/bits/stl_tree.h [_GLIBCXX_INLINE_VERSION] diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index 188fcc265e1..c18bcb6f72d 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -88,24 +88,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct tuple_size; // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2313. tuple_size should always derive from integral_constant // 2770. tuple_size specialization is not SFINAE compatible - template - struct __tuple_size_cv_impl { }; - template - struct __tuple_size_cv_impl<_Tp, __void_t::value)>> - : integral_constant::value> { }; + template::type, + typename = typename enable_if::value>::type, + size_t = tuple_size<_Tp>::value> + using __enable_if_has_tuple_size = _Tp; - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 2313. tuple_size should always derive from integral_constant template - struct tuple_size : __tuple_size_cv_impl<_Tp> { }; + struct tuple_size> + : public tuple_size<_Tp> { }; template - struct tuple_size : __tuple_size_cv_impl<_Tp> { }; + struct tuple_size> + : public tuple_size<_Tp> { }; template - struct tuple_size : __tuple_size_cv_impl<_Tp> { }; + struct tuple_size> + : public tuple_size<_Tp> { }; /// Gives the type of the ith element of a given tuple type. template diff --git a/libstdc++-v3/testsuite/20_util/tuple/78939.cc b/libstdc++-v3/testsuite/20_util/tuple/78939.cc new file mode 100644 index 00000000000..bab143b387f --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/78939.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++1z } } + +// PR libstdc++/78939 + +#include + +struct A { int i, j; }; + +int +test01() +{ + A a{}; + const auto [i, j] = a; + return i + j; +} + +int +test02() +{ + A a{}; + volatile auto [i, j] = a; + return i + j; +} + +int +test03() +{ + A a{}; + const volatile auto [i, j] = a; + return i + j; +} diff --git a/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size_neg.cc b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size_neg.cc new file mode 100644 index 00000000000..450ed894c4e --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/tuple/cv_tuple_size_neg.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile { target c++11 } } + +#include + +// PR libstdc++/78939 + +std::tuple_size ic; // { dg-error "incomplete" } +std::tuple_size iv; // { dg-error "incomplete" } +std::tuple_size icv; // { dg-error "incomplete" } + +struct A { }; +std::tuple_size ac; // { dg-error "incomplete" } +std::tuple_size av; // { dg-error "incomplete" } +std::tuple_size acv; // { dg-error "incomplete" } + +std::tuple_size vc; // { dg-error "incomplete" } +std::tuple_size vv; // { dg-error "incomplete" } +std::tuple_size vcv; // { dg-error "incomplete" }