PetteriAimonen created this revision.
Herald added a reviewer: EricWF.

Previously std::map ignored out-of-bounds access when exceptions were
disabled. Other containers such as std::vector use throw_out_of_range()
which will terminate the program if exceptions are disabled.


https://reviews.llvm.org/D40834

Files:
  include/map


Index: include/map
===================================================================
--- include/map
+++ include/map
@@ -1371,10 +1371,8 @@
 {
     __parent_pointer __parent;
     __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
-#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__child == nullptr)
-        throw out_of_range("map::at:  key not found");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+        _VSTD::__throw_out_of_range("map::at:  key not found");
     return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 
@@ -1384,10 +1382,8 @@
 {
     __parent_pointer __parent;
     __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
-#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__child == nullptr)
-        throw out_of_range("map::at:  key not found");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+        _VSTD::__throw_out_of_range("map::at:  key not found");
     return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 


Index: include/map
===================================================================
--- include/map
+++ include/map
@@ -1371,10 +1371,8 @@
 {
     __parent_pointer __parent;
     __node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
-#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__child == nullptr)
-        throw out_of_range("map::at:  key not found");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+        _VSTD::__throw_out_of_range("map::at:  key not found");
     return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 
@@ -1384,10 +1382,8 @@
 {
     __parent_pointer __parent;
     __node_base_pointer __child = __tree_.__find_equal(__parent, __k);
-#ifndef _LIBCPP_NO_EXCEPTIONS
     if (__child == nullptr)
-        throw out_of_range("map::at:  key not found");
-#endif  // _LIBCPP_NO_EXCEPTIONS
+        _VSTD::__throw_out_of_range("map::at:  key not found");
     return static_cast<__node_pointer>(__child)->__value_.__cc.second;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to