public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Avoid unnecessary inclusion of <stdexcept> header
@ 2019-06-06 15:38 Jonathan Wakely
  2019-06-17  8:21 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2019-06-06 15:38 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

This can greatly reduce the amount of preprocessed code that is included
by other headers, because <stdexcept> depends on <string> which is huge.

	* include/std/array: Do not include <stdexcept>.
	* include/std/optional: Include <exception> and
	<bits/exception_defines.h> instead of <stdexcept>.

Preprocessed line counts for C++17 mode:

       <tuple> <memory> <map>
Before   25774    32453 31616
After     9925    23194 19062

Tested x86_64-linux, committed to trunk.

Once we have a gcc-10/porting_to.html page I'll note this change
there, because code relying on std::string and std::allocator being
defined by transitive includes will need to include the right headers.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3721 bytes --]

commit 9eb6db53fb072e20b1d54b16d8c1c77638c934e5
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jun 6 15:34:56 2019 +0000

    Avoid unnecessary inclusion of <stdexcept> header
    
    This can greatly reduce the amount of preprocessed code that is included
    by other headers, because <stdexcept> depends on <string> which is huge.
    
            * include/std/array: Do not include <stdexcept>.
            * include/std/optional: Include <exception> and
            <bits/exception_defines.h> instead of <stdexcept>.
            * testsuite/20_util/function_objects/searchers.cc: Include <cctype>
            for std::isalnum.
            * testsuite/20_util/tuple/cons/deduction.cc: Include <memory> for
            std::allocator.
            * testsuite/23_containers/map/erasure.cc: Include <string>.
            * testsuite/23_containers/unordered_map/erasure.cc: Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272011 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array
index 02c6f4b4dbe..230e2b0f593 100644
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -36,7 +36,7 @@
 #else
 
 #include <utility>
-#include <stdexcept>
+#include <bits/functexcept.h>
 #include <bits/stl_algobase.h>
 #include <bits/range_access.h>
 
diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index ae825d3e327..79cd6c97019 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -35,10 +35,10 @@
 
 #include <utility>
 #include <type_traits>
-#include <stdexcept>
+#include <exception>
 #include <new>
 #include <initializer_list>
-#include <bits/functexcept.h>
+#include <bits/exception_defines.h>
 #include <bits/functional_hash.h>
 #include <bits/enable_special_members.h>
 
diff --git a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
index aae21d28d3a..fc278860f5c 100644
--- a/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
+++ b/libstdc++-v3/testsuite/20_util/function_objects/searchers.cc
@@ -19,6 +19,7 @@
 
 #include <functional>
 #include <cstring>
+#include <cctype>
 #ifdef _GLIBCXX_USE_WCHAR_T
 # include <cwchar>
 #endif
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
index fa91f8fa539..eb3f2f3d6ab 100644
--- a/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/deduction.cc
@@ -19,6 +19,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <tuple>
+#include <memory>
 
 template<typename T, typename U> struct require_same;
 template<typename T> struct require_same<T, T> { using type = void; };
diff --git a/libstdc++-v3/testsuite/23_containers/map/erasure.cc b/libstdc++-v3/testsuite/23_containers/map/erasure.cc
index d8a57160865..5b211c3602b 100644
--- a/libstdc++-v3/testsuite/23_containers/map/erasure.cc
+++ b/libstdc++-v3/testsuite/23_containers/map/erasure.cc
@@ -19,6 +19,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <map>
+#include <string>
 #include <testsuite_hooks.h>
 
 #ifndef __cpp_lib_erase_if
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc
index 35190a0d19e..17bb940f00f 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc
@@ -19,6 +19,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <unordered_map>
+#include <string>
 #include <testsuite_hooks.h>
 
 #ifndef __cpp_lib_erase_if

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Avoid unnecessary inclusion of <stdexcept> header
  2019-06-06 15:38 [PATCH] Avoid unnecessary inclusion of <stdexcept> header Jonathan Wakely
@ 2019-06-17  8:21 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-06-17  8:21 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

On 06/06/19 16:38 +0100, Jonathan Wakely wrote:
>This can greatly reduce the amount of preprocessed code that is included
>by other headers, because <stdexcept> depends on <string> which is huge.
>
>	* include/std/array: Do not include <stdexcept>.
>	* include/std/optional: Include <exception> and
>	<bits/exception_defines.h> instead of <stdexcept>.
>
>Preprocessed line counts for C++17 mode:
>
>      <tuple> <memory> <map>
>Before   25774    32453 31616
>After     9925    23194 19062
>
>Tested x86_64-linux, committed to trunk.
>
>Once we have a gcc-10/porting_to.html page I'll note this change
>there, because code relying on std::string and std::allocator being
>defined by transitive includes will need to include the right headers.

After this change some tests fail without PCH, because they weren't
including what they use.

Tested x86_64-linux, committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 5914 bytes --]

commit 9462a83e712b1e8621ffee998ccd3291df889c4b
Author: redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Mon Jun 17 08:18:17 2019 +0000

    Fix tests that fail without PCH
    
    The recent change to stop transitively including <string> broke some
    tests, but only when the library is configured without PCH, because
    otherwise the <string> header still gets included via the precompiled
    <bits/stdc++.h> header.
    
            * testsuite/20_util/bad_function_call/what.cc: Include <string> header
            for std::string.
            * testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc: Likewise.
            * testsuite/20_util/tuple/cons/allocator_with_any.cc: Include <memory>
            header for std::allocator.
            * testsuite/23_containers/array/tuple_interface/tuple_element.cc: Add
            using-declaration for std::size_t.
            * testsuite/23_containers/array/tuple_interface/tuple_size.cc:
            Likewise.
            * testsuite/23_containers/deque/cons/55977.cc: Include <istream> for
            std::istream.
            * testsuite/23_containers/vector/cons/55977.cc: Likewise.
            * testsuite/experimental/map/erasure.cc: Include <string> for
            std::string.
            * testsuite/experimental/unordered_map/erasure.cc: Likewise.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@272376 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/libstdc++-v3/testsuite/20_util/bad_function_call/what.cc b/libstdc++-v3/testsuite/20_util/bad_function_call/what.cc
index e17b42feedd..229c7ef1cab 100644
--- a/libstdc++-v3/testsuite/20_util/bad_function_call/what.cc
+++ b/libstdc++-v3/testsuite/20_util/bad_function_call/what.cc
@@ -18,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <functional>
+#include <string>
 #include <testsuite_hooks.h>
 
 int main()
diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc
index f9c44cd60f3..a32a5c91943 100644
--- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc
+++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/weak_ptr_expired.cc
@@ -20,6 +20,7 @@
 // 20.6.6.2 Template class shared_ptr [util.smartptr.shared]
 
 #include <memory>
+#include <string>
 #include <testsuite_hooks.h>
 
 struct A { };
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc
index 655b5328bda..154ec9161bd 100644
--- a/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/allocator_with_any.cc
@@ -23,6 +23,7 @@
 // this test may begin to fail.
 
 #include <tuple>
+#include <memory>
 #include <experimental/any>
 #include <testsuite_hooks.h>
 
diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
index b6fda44a3c5..e8b6bc12e77 100644
--- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element.cc
@@ -29,7 +29,7 @@ test01()
   // This relies on the fact that <utility> includes <type_traits>:
   using std::is_same;
 
-  const size_t len = 3;
+  const std::size_t len = 3;
   typedef array<int, len> array_type;
 
   static_assert(is_same<tuple_element<0, array_type>::type, int>::value, "" );
diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc
index aedd5fc2a2d..740c42a8914 100644
--- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc
+++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_size.cc
@@ -26,6 +26,7 @@ test01()
 {
   using std::array;
   using std::tuple_size;
+  using std::size_t;
   // This relies on the fact that <utility> includes <type_traits>:
   using std::is_same;
 
diff --git a/libstdc++-v3/testsuite/23_containers/deque/cons/55977.cc b/libstdc++-v3/testsuite/23_containers/deque/cons/55977.cc
index 492aedf97b4..5ab516a2950 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/cons/55977.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/cons/55977.cc
@@ -21,6 +21,7 @@
 #include <utility>
 #include <deque>
 #include <iterator>
+#include <istream>
 
 template <class T>
 struct MyAllocator
diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/55977.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/55977.cc
index f7767923592..efa03b1edfd 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/cons/55977.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/cons/55977.cc
@@ -21,6 +21,7 @@
 #include <utility>
 #include <vector>
 #include <iterator>
+#include <istream>
 
 template <class T>
 struct MyAllocator
diff --git a/libstdc++-v3/testsuite/experimental/map/erasure.cc b/libstdc++-v3/testsuite/experimental/map/erasure.cc
index c636fcbb1b5..aa3d42da299 100644
--- a/libstdc++-v3/testsuite/experimental/map/erasure.cc
+++ b/libstdc++-v3/testsuite/experimental/map/erasure.cc
@@ -18,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <experimental/map>
+#include <string>
 #include <testsuite_hooks.h>
 
 auto is_odd_pair = [](const std::pair<const int, std::string>& p)
diff --git a/libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc b/libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc
index c08fa315271..79a42ffbdf9 100644
--- a/libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc
+++ b/libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc
@@ -18,6 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include <experimental/unordered_map>
+#include <string>
 #include <testsuite_hooks.h>
 
 auto is_odd_pair = [](const std::pair<const int, std::string>& p)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-17  8:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-06 15:38 [PATCH] Avoid unnecessary inclusion of <stdexcept> header Jonathan Wakely
2019-06-17  8:21 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).