This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Nothrows for functional_hash


Hi,
functional_hash seems to be quite interesting example.  There are
explicit instantiations of () operand that are pure and nothrow.
But I am not sure if it is safe to mark () operator of template itself,
or is there reason why user can't get it throwing?

If it is unsafe, then G++ is complaining when the instantiations
are marked by throw () while operator itself is not.  This is not
the case of function attributes, so adding nothrow attribute here
instead of throw () marker works and gets the work done.

Does this seem sane?  There are couple other similar testcases for
other explicitly instantiated template methods.

Tested on x86_64-linux

Honza
	* include/tr1_impl/functional_hash.h (explicit instantiations of ()
	operator): Mark by pure and nothrow attribute.
	* include/bits/c++config (_GLIBCXX_NOTHROW_ATTR): New macro.
Index: include/tr1_impl/functional_hash.h
===================================================================
--- include/tr1_impl/functional_hash.h	(revision 146724)
+++ include/tr1_impl/functional_hash.h	(working copy)
@@ -157,25 +157,25 @@
 
   /// Explicit specializations for long double.
   template<>
-    size_t
+    _GLIBCXX_PURE _GLIBCXX_NOTHROW_ATTR size_t
     hash<long double>::operator()(long double __val) const;
 
   /// Explicit specialization of member operator for non-builtin types.
   template<>
-    size_t
+    _GLIBCXX_PURE _GLIBCXX_NOTHROW_ATTR size_t
     hash<string>::operator()(string) const;
 
   template<>
-    size_t
+    _GLIBCXX_PURE _GLIBCXX_NOTHROW_ATTR size_t
     hash<const string&>::operator()(const string&) const;
 
 #ifdef _GLIBCXX_USE_WCHAR_T
   template<>
-    size_t
+    _GLIBCXX_PURE _GLIBCXX_NOTHROW_ATTR size_t
     hash<wstring>::operator()(wstring) const;
 
   template<>
-    size_t
+    _GLIBCXX_PURE _GLIBCXX_NOTHROW_ATTR size_t
     hash<const wstring&>::operator()(const wstring&) const;
 #endif
 
Index: include/bits/c++config
===================================================================
--- include/bits/c++config	(revision 146724)
+++ include/bits/c++config	(working copy)
@@ -334,4 +334,8 @@
 # endif
 #endif
 
+#ifndef _GLIBCXX_NOTHROW_ATTR
+# define _GLIBCXX_NOTHROW_ATTR __attribute__((__nothrow__))
+#endif
+
 // End of prewritten config; the discovered settings follow.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]