From: Jonathan Wakely Date: Wed, 10 Feb 2016 11:25:33 +0000 (+0000) Subject: Constrain std::valarray functions and operators X-Git-Tag: releases/gcc-4.9.4~349 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d879d47ef3bc981b4228e18542d035633d5a11b;p=thirdparty%2Fgcc.git Constrain std::valarray functions and operators PR libstdc++/69116 * include/bits/valarray_before.h (__fun, __fun_with_valarray): Only define result_type for types which can be safely used with valarrays. * testsuite/26_numerics/valarray/69116.cc: New. From-SVN: r233265 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7f48f89ddd6b..24d6caea8c71 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2016-02-10 Jonathan Wakely + + PR libstdc++/69116 + * include/bits/valarray_before.h (__fun, __fun_with_valarray): Only + define result_type for types which can be safely used with valarrays. + * testsuite/26_numerics/valarray/69116.cc: New. + 2016-01-18 Jonathan Wakely PR libstdc++/60637 diff --git a/libstdc++-v3/include/bits/valarray_before.h b/libstdc++-v3/include/bits/valarray_before.h index fb5ec74ee53d..971ed82cb4ce 100644 --- a/libstdc++-v3/include/bits/valarray_before.h +++ b/libstdc++-v3/include/bits/valarray_before.h @@ -331,14 +331,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return pow(__x, __y); } }; + template + struct __fun_with_valarray + { + typedef _Tp result_type; + }; + + template + struct __fun_with_valarray<_Tp, false> + { + // No result type defined for invalid value types. + }; // We need these bits in order to recover the return type of // some functions/operators now that we're no longer using // function templates. template - struct __fun + struct __fun : __fun_with_valarray<_Tp> { - typedef _Tp result_type; }; // several specializations for relational operators. diff --git a/libstdc++-v3/testsuite/26_numerics/valarray/69116.cc b/libstdc++-v3/testsuite/26_numerics/valarray/69116.cc new file mode 100644 index 000000000000..ef9826778cf0 --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/valarray/69116.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2016 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 } +// { dg-options "-std=gnu++98" } + +// libstdc++/69116 + +#include +#include + +template + void foo(const T&) { } + +struct X : std::exception // makes namespace std an associated namespace +{ + virtual void pure() = 0; + + typedef void(*func_type)(const X&); + + void operator+(func_type) const; + void operator-(func_type) const; + void operator*(func_type) const; + void operator/(func_type) const; + void operator%(func_type) const; + void operator<<(func_type) const; + void operator>>(func_type) const; +}; + +void foo(X& x) +{ + x + foo; + x - foo; + x * foo; + x / foo; + x % foo; + x << foo; + x >> foo; +}