25c7f1
2016-02-10  Jonathan Wakely  <jwakely@redhat.com>
25c7f1
25c7f1
	PR libstdc++/69116
25c7f1
	* include/bits/valarray_before.h (__fun, __fun_with_valarray): Only
25c7f1
	define result_type for types which can be safely used with valarrays.
25c7f1
	* testsuite/26_numerics/valarray/69116.cc: New.
25c7f1
25c7f1
--- libstdc++-v3/include/bits/valarray_before.h	(revision 233264)
25c7f1
+++ libstdc++-v3/include/bits/valarray_before.h	(revision 233265)
25c7f1
@@ -331,14 +331,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
25c7f1
       { return pow(__x, __y); }
25c7f1
   };
25c7f1
 
25c7f1
+  template<typename _Tp, bool _IsValidValarrayValue = !__is_abstract(_Tp)>
25c7f1
+    struct __fun_with_valarray
25c7f1
+    {
25c7f1
+      typedef _Tp result_type;
25c7f1
+    };
25c7f1
+
25c7f1
+  template<typename _Tp>
25c7f1
+    struct __fun_with_valarray<_Tp, false>
25c7f1
+    {
25c7f1
+      // No result type defined for invalid value types.
25c7f1
+    };
25c7f1
 
25c7f1
   // We need these bits in order to recover the return type of
25c7f1
   // some functions/operators now that we're no longer using
25c7f1
   // function templates.
25c7f1
   template<typename, typename _Tp>
25c7f1
-    struct __fun
25c7f1
+    struct __fun : __fun_with_valarray<_Tp>
25c7f1
     {
25c7f1
-      typedef _Tp result_type;
25c7f1
     };
25c7f1
 
25c7f1
   // several specializations for relational operators.
25c7f1
--- libstdc++-v3/testsuite/26_numerics/valarray/69116.cc	(nonexistent)
25c7f1
+++ libstdc++-v3/testsuite/26_numerics/valarray/69116.cc	(revision 233265)
25c7f1
@@ -0,0 +1,53 @@
25c7f1
+// Copyright (C) 2016 Free Software Foundation, Inc.
25c7f1
+//
25c7f1
+// This file is part of the GNU ISO C++ Library.  This library is free
25c7f1
+// software; you can redistribute it and/or modify it under the
25c7f1
+// terms of the GNU General Public License as published by the
25c7f1
+// Free Software Foundation; either version 3, or (at your option)
25c7f1
+// any later version.
25c7f1
+
25c7f1
+// This library is distributed in the hope that it will be useful,
25c7f1
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
25c7f1
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25c7f1
+// GNU General Public License for more details.
25c7f1
+
25c7f1
+// You should have received a copy of the GNU General Public License along
25c7f1
+// with this library; see the file COPYING3.  If not see
25c7f1
+// <http://www.gnu.org/licenses/>.
25c7f1
+
25c7f1
+// { dg-do compile }
25c7f1
+// { dg-options "-std=gnu++98" }
25c7f1
+
25c7f1
+// libstdc++/69116
25c7f1
+
25c7f1
+#include <exception>
25c7f1
+#include <valarray>
25c7f1
+
25c7f1
+template<typename T>
25c7f1
+  void foo(const T&) { }
25c7f1
+
25c7f1
+struct X : std::exception // makes namespace std an associated namespace
25c7f1
+{
25c7f1
+  virtual void pure() = 0;
25c7f1
+
25c7f1
+  typedef void(*func_type)(const X&);
25c7f1
+
25c7f1
+  void operator+(func_type) const;
25c7f1
+  void operator-(func_type) const;
25c7f1
+  void operator*(func_type) const;
25c7f1
+  void operator/(func_type) const;
25c7f1
+  void operator%(func_type) const;
25c7f1
+  void operator<<(func_type) const;
25c7f1
+  void operator>>(func_type) const;
25c7f1
+};
25c7f1
+
25c7f1
+void foo(X& x)
25c7f1
+{
25c7f1
+  x + foo;
25c7f1
+  x - foo;
25c7f1
+  x * foo;
25c7f1
+  x / foo;
25c7f1
+  x % foo;
25c7f1
+  x << foo;
25c7f1
+  x >> foo;
25c7f1
+}