From patchwork Sun Nov 6 23:25:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 123982 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BFB7DB6F6B for ; Mon, 7 Nov 2011 10:26:10 +1100 (EST) Received: (qmail 2188 invoked by alias); 6 Nov 2011 23:26:07 -0000 Received: (qmail 2132 invoked by uid 22791); 6 Nov 2011 23:26:03 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ww0-f41.google.com (HELO mail-ww0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 06 Nov 2011 23:25:48 +0000 Received: by wwf27 with SMTP id 27so4177261wwf.2 for ; Sun, 06 Nov 2011 15:25:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.54.83 with SMTP id h61mr3051330wec.6.1320621946529; Sun, 06 Nov 2011 15:25:46 -0800 (PST) Received: by 10.216.63.83 with HTTP; Sun, 6 Nov 2011 15:25:46 -0800 (PST) Date: Sun, 6 Nov 2011 23:25:46 +0000 Message-ID: Subject: [v3] fix autoconf examples for testing C++11 support From: Jonathan Wakely To: "libstdc++" , gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The autoconf examples at http://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html#id541888 are incorrect, relying on pre-standard semantics for rvalue references, and missing out several C++11 headers. This patch corrects those examples. This also tweaks some markup in the file, and adds some xml:id attributes to ensure stable anchors when the HTML is regenerated, so the link above will become http://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html#backwards.third.support_cxx11 and stay the same in future. * doc/xml/manual/backwards_compatibility.xml: Fix autoconf tests for C++11 compiler features and library headers. Add stable id attributes. Use element for headers and surround in angle brackets. Use for classes. * doc/html/*: Regenerate. Committed to trunk. Index: doc/xml/manual/backwards_compatibility.xml =================================================================== --- doc/xml/manual/backwards_compatibility.xml (revision 181041) +++ doc/xml/manual/backwards_compatibility.xml (working copy) @@ -42,24 +42,24 @@ Committee couldn't include everything, a Portability notes and known implementation limitations are as follows. -
No <code>ios_base</code> +
No <code>ios_base</code> At least some older implementations don't have std::ios_base, so you should use std::ios::badbit, std::ios::failbit and std::ios::eofbit and std::ios::goodbit.
-
No <code>cout</code> in <code>ostream.h</code>, no <code>cin</code> in <code>istream.h</code> +
No <code>cout</code> in <filename class="headerfile"><ostream.h></filename>, no <code>cin</code> in <filename class="headerfile"><istream.h></filename> In earlier versions of the standard, - fstream.h, - ostream.h - and istream.h + <fstream.h>, + <ostream.h> + and <istream.h> used to define cout, cin and so on. ISO C++ specifies that one needs to include - iostream + <iostream> explicitly to get the required definitions. Some include adjustment may be required. @@ -96,7 +96,7 @@ considered replaced and rewritten. Portability notes and known implementation limitations are as follows. -
Namespace <code>std::</code> not supported +
Namespace <code>std::</code> not supported @@ -114,7 +114,7 @@ considered replaced and rewritten. First, see if the compiler has a flag for this. Namespace back-portability-issues are generally not a problem for g++ compilers that do not have libstdc++ in std::, as the - compilers use -fno-honor-std (ignore + compilers use (ignore std::, :: = std::) by default. That is, the responsibility for enabling or disabling std:: is on the user; the maintainer does not have to care about it. This @@ -182,7 +182,7 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [
-
Illegal iterator usage +
Illegal iterator usage The following illustrate implementation-allowed illegal iterator @@ -212,12 +212,12 @@ AC_DEFUN([AC_CXX_NAMESPACE_STD], [
-
<code>isspace</code> from <filename class="headerfile">cctype</filename> is a macro +<section xml:id="backwards.second.isspace"><info><title><code>isspace</code> from <filename class="headerfile"><cctype></filename> is a macro - Glibc 2.0.x and 2.1.x define ctype.h functionality as macros + Glibc 2.0.x and 2.1.x define <ctype.h> functionality as macros (isspace, isalpha etc.). @@ -242,7 +242,7 @@ std:: (__ctype_b[(int) ( ( 'X' ) )] & A solution is to modify a header-file so that the compiler tells - ctype.h to define functions + <ctype.h> to define functions instead of macros: @@ -254,20 +254,21 @@ std:: (__ctype_b[(int) ( ( 'X' ) )] & - Then, include ctype.h + Then, include <ctype.h> Another problem arises if you put a using namespace - std; declaration at the top, and include ctype.h. This will result in - ambiguities between the definitions in the global namespace - (ctype.h) and the + std; declaration at the top, and include + <ctype.h>. This will + result in ambiguities between the definitions in the global namespace + (<ctype.h>) and the definitions in namespace std:: (<cctype>).
-
No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code> +
No <code>vector::at</code>, <code>deque::at</code>, <code>string::at</code> @@ -304,7 +305,7 @@ AC_DEFINE(HAVE_CONTAINER_AT)],
-
No <code>std::char_traits<char>::eof</code> +
No <code>std::char_traits<char>::eof</code> @@ -321,7 +322,7 @@ AC_DEFINE(HAVE_CONTAINER_AT)],
-
No <code>string::clear</code> +
No <code>string::clear</code> @@ -351,7 +352,7 @@ erase(size_type __pos = 0, size_type __n
-
+<section xml:id="backwards.second.ostreamform_istreamscan"><info><title> Removal of <code>ostream::form</code> and <code>istream::scan</code> extensions @@ -362,14 +363,14 @@ erase(size_type __pos = 0, size_type __n
-
No <code>basic_stringbuf</code>, <code>basic_stringstream</code> +
No <code>basic_stringbuf</code>, <code>basic_stringstream</code> Although the ISO standard i/ostringstream-classes are - provided, (sstream), for + provided, (<sstream>), for compatibility with older implementations the pre-ISO - i/ostrstream (strstream) interface is also provided, + i/ostrstream (<strstream>) interface is also provided, with these caveats: @@ -490,7 +491,7 @@ particular info iostream.
-
Little or no wide character support +
Little or no wide character support Classes wstring and @@ -499,7 +500,7 @@ particular info iostream.
-
No templatized iostreams +
No templatized iostreams Classes wfilebuf and @@ -507,7 +508,7 @@ particular info iostream.
-
Thread safety issues +
Thread safety issues @@ -601,11 +602,12 @@ libstdc++-v3. Portability notes and known implementation limitations are as follows. -
Pre-ISO headers moved to backwards or removed +
Pre-ISO headers moved to backwards or removed The pre-ISO C++ headers - (iostream.h, defalloc.h etc.) are + (<iostream.h>, + <defalloc.h> etc.) are available, unlike previous libstdc++ versions, but inclusion generates a warning that you are using deprecated headers. @@ -681,29 +683,30 @@ AC_DEFUN([AC_HEADER_PRE_STDCXX], [ Porting between pre-ISO headers and ISO headers is simple: headers -like vector.h can be replaced with vector and a using +like <vector.h> can be replaced with <vector> and a using directive using namespace std; can be put at the global scope. This should be enough to get this code compiling, assuming the other usage is correct.
-
Extension headers hash_map, hash_set moved to ext or backwards +
Extension headers hash_map, hash_set moved to ext or backwards At this time most of the features of the SGI STL extension have been replaced by standardized libraries. - In particular, the unordered_map and - unordered_set containers of TR1 and C++ 2011 are suitable - replacements for the non-standard hash_map and - hash_set containers in the SGI STL. + In particular, the unordered_map and + unordered_set containers of TR1 and C++ 2011 + are suitable replacements for the non-standard + hash_map and hash_set + containers in the SGI STL. - Header files hash_map and hash_set moved -to ext/hash_map and ext/hash_set, + Header files <hash_map> and <hash_set> moved +to <ext/hash_map> and <ext/hash_set>, respectively. At the same time, all types in these files are enclosed in namespace __gnu_cxx. Later versions deprecate -these files, and suggest using TR1's unordered_map -and unordered_set instead. +these files, and suggest using TR1's <unordered_map> +and <unordered_set> instead. The extensions are no longer in the global or std @@ -779,7 +782,7 @@ AC_DEFUN([AC_HEADER_EXT_HASH_SET], [
-
No <code>ios::nocreate/ios::noreplace</code>. +<section xml:id="backwards.third.nocreate_noreplace"><info><title>No <code>ios::nocreate/ios::noreplace</code>. @@ -798,7 +801,7 @@ and trunc (except for
-
+<section xml:id="backwards.third.streamattach"><info><title> No <code>stream::attach(int fd)</code> @@ -820,7 +823,7 @@ No stream::attach(int fd) An extension is available that implements this. - ext/stdio_filebuf.h contains a derived class called + <ext/stdio_filebuf.h> contains a derived class called __gnu_cxx::stdio_filebuf. This class can be constructed from a C FILE* or a file descriptor, and provides the fd() function. @@ -833,7 +836,7 @@ No stream::attach(int fd)
-
+<section xml:id="backwards.third.support_cxx98"><info><title> Support for C++98 dialect. @@ -909,7 +912,7 @@ AC_DEFUN([AC_HEADER_STDCXX_98], [
-
+<section xml:id="backwards.third.support_tr1"><info><title> Support for C++TR1 dialect. @@ -1001,7 +1004,7 @@ AC_DEFUN([AC_HEADER_TR1_UNORDERED_SET],
-
+<section xml:id="backwards.third.support_cxx11"><info><title> Support for C++11 dialect. @@ -1018,9 +1021,9 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ AC_LANG_CPLUSPLUS AC_TRY_COMPILE([ template <typename T> - struct check + struct check final { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); + static constexpr T value{ __cplusplus }; }; typedef check<check<bool>> right_angle_brackets; @@ -1029,8 +1032,10 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ decltype(a) b; typedef check<int> check_type; - check_type c; - check_type&& cr = c;],, + check_type c{}; + check_type&& cr = static_cast<check_type&&>(c); + + static_assert(check_type::value == 201103L, "C++11 compiler");],, ac_cv_cxx_compile_cxx11_native=yes, ac_cv_cxx_compile_cxx11_native=no) AC_LANG_RESTORE ]) @@ -1043,9 +1048,9 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ CXXFLAGS="$CXXFLAGS -std=c++11" AC_TRY_COMPILE([ template <typename T> - struct check + struct check final { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); + static constexpr T value{ __cplusplus }; }; typedef check<check<bool>> right_angle_brackets; @@ -1054,8 +1059,10 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ decltype(a) b; typedef check<int> check_type; - check_type c; - check_type&& cr = c;],, + check_type c{}; + check_type&& cr = static_cast<check_type&&>(c); + + static_assert(check_type::value == 201103L, "C++11 compiler");],, ac_cv_cxx_compile_cxx11_cxx=yes, ac_cv_cxx_compile_cxx11_cxx=no) CXXFLAGS="$ac_save_CXXFLAGS" AC_LANG_RESTORE @@ -1069,9 +1076,9 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ CXXFLAGS="$CXXFLAGS -std=gnu++11" AC_TRY_COMPILE([ template <typename T> - struct check + struct check final { - static_assert(sizeof(int) <= sizeof(T), "not big enough"); + static constexpr T value{ __cplusplus }; }; typedef check<check<bool>> right_angle_brackets; @@ -1080,8 +1087,10 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ decltype(a) b; typedef check<int> check_type; - check_type c; - check_type&& cr = c;],, + check_type c{}; + check_type&& cr = static_cast<check_type&&>(c); + + static_assert(check_type::value == 201103L, "C++11 compiler");],, ac_cv_cxx_compile_cxx11_gxx=yes, ac_cv_cxx_compile_cxx11_gxx=no) CXXFLAGS="$ac_save_CXXFLAGS" AC_LANG_RESTORE @@ -1097,6 +1106,8 @@ AC_DEFUN([AC_COMPILE_STDCXX_11], [ Check for library coverage of the C++2011 standard. + (Some library headers are commented out in this check, they are + not currently provided by libstdc++). @@ -1124,6 +1135,7 @@ AC_DEFUN([AC_HEADER_STDCXX_11], [ #include <cmath> #include <csetjmp> #include <csignal> + // #include <cstdalign> #include <cstdarg> #include <cstdbool> #include <cstddef> @@ -1133,21 +1145,29 @@ AC_DEFUN([AC_HEADER_STDCXX_11], [ #include <cstring> #include <ctgmath> #include <ctime> + // #include <cuchar> #include <cwchar> #include <cwctype> #include <algorithm> #include <array> + #include <atomic> #include <bitset> + #include <chrono> + // #include <codecvt> #include <complex> + #include <condition_variable> #include <deque> #include <exception> + #include <forward_list> #include <fstream> #include <functional> + #include <future> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> + #include <initializer_list> #include <istream> #include <iterator> #include <limits> @@ -1155,19 +1175,25 @@ AC_DEFUN([AC_HEADER_STDCXX_11], [ #include <locale> #include <map> #include <memory> + #include <mutex> #include <new> #include <numeric> #include <ostream> #include <queue> #include <random> + #include <ratio> #include <regex> + #include <scoped_allocator> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> + #include <system_error> + #include <thread> #include <tuple> + #include <typeindex> #include <typeinfo> #include <type_traits> #include <unordered_map> @@ -1186,7 +1212,8 @@ AC_DEFUN([AC_HEADER_STDCXX_11], [ ]) -As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For <unordered_map> +As is the case for TR1 support, these autoconf macros can be made for a finer-grained, per-header-file check. For +<unordered_map> @@ -1243,8 +1270,8 @@ AC_DEFUN([AC_HEADER_UNORDERED_SET], [
-
- Container::iterator_type is not necessarily Container::value_type* +<section xml:id="backwards.third.iterator_type"><info><title> + <code>Container::iterator_type</code> is not necessarily <code>Container::value_type*</code>