llvm.org GIT mirror llvm / f72d1f1
Move to C++14 Summary: I just bumped the minimum compiler versions to support C++14 in D66188. Following [our process](http://llvm.org/docs/DeveloperPolicy.html#toolchain) and [our previous agreement](http://lists.llvm.org/pipermail/llvm-dev/2019-January/129452.html), I'm now officially bumping the C++ version to 14 and updating the documentation. Subscribers: mgorny, jkorous, dexonsmith, llvm-commits, chandlerc, thakis, EricWF, jyknight, lhames, JDevlieghere Tags: #llvm Differential Revision: https://reviews.llvm.org/D66195 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368887 91177308-0d34-0410-b5e6-96231b3b80d8 JF Bastien a month ago
4 changed file(s) with 16 addition(s) and 98 deletion(s). Raw diff Collapse all Expand all
1717 set(LINKER_IS_LLD_LINK FALSE)
1818 endif()
1919
20 set(LLVM_CXX_STD_default "c++11")
20 set(LLVM_CXX_STD_default "c++14")
2121 # Preserve behaviour of legacy cache variables
2222 if (LLVM_ENABLE_CXX1Y)
2323 set(LLVM_CXX_STD_default "c++1y")
5555 C++ Standard Versions
5656 ---------------------
5757
58 LLVM, Clang, and LLD are currently written using C++11 conforming code,
58 LLVM, Clang, and LLD are currently written using C++14 conforming code,
5959 although we restrict ourselves to features which are available in the major
6060 toolchains supported as host compilers. The LLDB project is even more
6161 aggressive in the set of host compilers supported and thus uses still more
6262 features. Regardless of the supported features, code is expected to (when
63 reasonable) be standard, portable, and modern C++11 code. We avoid unnecessary
63 reasonable) be standard, portable, and modern C++14 code. We avoid unnecessary
6464 vendor-specific extensions, etc.
6565
6666 C++ Standard Library
7777 avoided. Also, there is much more detailed information on these subjects in the
7878 :doc:`ProgrammersManual`.
7979
80 Supported C++11 Language and Library Features
80 Supported C++14 Language and Library Features
8181 ---------------------------------------------
8282
83 While LLVM, Clang, and LLD use C++11, not all features are available in all of
83 While LLVM, Clang, and LLD use C++14, not all features are available in all of
8484 the toolchains which we support. The set of features supported for use in LLVM
8585 is the intersection of those supported in the minimum requirements described
8686 in the :doc:`GettingStarted` page, section `Software`.
9191 Each toolchain provides a good reference for what it accepts:
9292
9393 * Clang: https://clang.llvm.org/cxx_status.html
94 * GCC: https://gcc.gnu.org/projects/cxx-status.html#cxx11
94 * GCC: https://gcc.gnu.org/projects/cxx-status.html#cxx14
9595 * MSVC: https://msdn.microsoft.com/en-us/library/hh567368.aspx
96
97 In most cases, the MSVC list will be the dominating factor. Here is a summary
98 of the features that are expected to work. Features not on this list are
99 unlikely to be supported by our host compilers.
100
101 * Rvalue references: N2118_
102
103 * But *not* Rvalue references for ``*this`` or member qualifiers (N2439_)
104
105 * Static assert: N1720_
106 * ``auto`` type deduction: N1984_, N1737_
107 * Trailing return types: N2541_
108 * Lambdas: N2927_
109
110 * But *not* lambdas with default arguments.
111
112 * ``decltype``: N2343_
113 * Nested closing right angle brackets: N1757_
114 * Extern templates: N1987_
115 * ``nullptr``: N2431_
116 * Strongly-typed and forward declarable enums: N2347_, N2764_
117 * Local and unnamed types as template arguments: N2657_
118 * Range-based for-loop: N2930_
119
120 * But ``{}`` are required around inner ``do {} while()`` loops. As a result,
121 ``{}`` are required around function-like macros inside range-based for
122 loops.
123
124 * ``override`` and ``final``: N2928_, N3206_, N3272_
125 * Atomic operations and the C++11 memory model: N2429_
126 * Variadic templates: N2242_
127 * Explicit conversion operators: N2437_
128 * Defaulted and deleted functions: N2346_
129 * Initializer lists: N2627_
130 * Delegating constructors: N1986_
131 * Default member initializers (non-static data member initializers): N2756_
132
133 * Feel free to use these wherever they make sense and where the `=`
134 syntax is allowed. Don't use braced initialization syntax.
135
136 .. _N2118: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2118.html
137 .. _N2439: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm
138 .. _N1720: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1720.html
139 .. _N1984: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1984.pdf
140 .. _N1737: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1737.pdf
141 .. _N2541: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2541.htm
142 .. _N2927: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2927.pdf
143 .. _N2343: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2343.pdf
144 .. _N1757: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
145 .. _N1987: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1987.htm
146 .. _N2431: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf
147 .. _N2347: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
148 .. _N2764: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf
149 .. _N2657: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm
150 .. _N2930: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2930.html
151 .. _N2928: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2928.htm
152 .. _N3206: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3206.htm
153 .. _N3272: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3272.htm
154 .. _N2429: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2429.htm
155 .. _N2242: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2242.pdf
156 .. _N2437: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2437.pdf
157 .. _N2346: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm
158 .. _N2627: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm
159 .. _N1986: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1986.pdf
160 .. _N2756: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2756.htm
161
162 The supported features in the C++11 standard libraries are less well tracked,
163 but also much greater. Most of the standard libraries implement most of C++11's
164 library. The most likely lowest common denominator is Linux support. For
165 libc++, the support is just poorly tested and undocumented but expected to be
166 largely complete. YMMV. For libstdc++, the support is documented in detail in
167 `the libstdc++ manual`_. There are some very minor missing facilities that are
168 unlikely to be common problems, and there are a few larger gaps that are worth
169 being aware of:
170
171 * Not all of the type traits are implemented
172 * No regular expression library.
173 * While most of the atomics library is well implemented, the fences are
174 missing. Fortunately, they are rarely needed.
175 * The locale support is incomplete.
176
177 Other than these areas you should assume the standard library is available and
178 working as expected until some build bot tells you otherwise. If you're in an
179 uncertain area of one of the above points, but you cannot test on a Linux
180 system, your best approach is to minimize your use of these features, and watch
181 the Linux build bots to find out if your usage triggered a bug. For example, if
182 you hit a type trait which doesn't work we can then add support to LLVM's
183 traits header to emulate it.
184
185 .. _the libstdc++ manual:
186 https://gcc.gnu.org/onlinedocs/gcc-4.8.0/libstdc++/manual/manual/status.html#status.iso.2011
18796
18897 Other Languages
18998 ---------------
806715 type is already obvious from the context. Another time when ``auto`` works well
807716 for these purposes is when the type would have been abstracted away anyways,
808717 often behind a container's typedef such as ``std::vector::iterator``.
718
719 Similarly, C++14 adds generic lambda expressions where parameter types can be
720 ``auto``. Use these where you would have used a template.
809721
810722 Beware unnecessary copies with ``auto``
811723 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
4141 #ifndef __has_builtin
4242 # define __has_builtin(x) 0
43 #endif
44
45 #ifdef __cplusplus
46 # if __cplusplus < 201402L
47 # error Expected C++14 or later.
48 # endif
4349 #endif
4450
4551 /// \macro LLVM_GNUC_PREREQ
191191 // If the compiler supports detecting whether a class is final, define
192192 // an LLVM_IS_FINAL macro. If it cannot be defined properly, this
193193 // macro will be left undefined.
194 #if __cplusplus >= 201402L || defined(_MSC_VER)
194 #if defined(__cplusplus) || defined(_MSC_VER)
195195 #define LLVM_IS_FINAL(Ty) std::is_final()
196196 #elif __has_feature(is_final) || LLVM_GNUC_PREREQ(4, 7, 0)
197197 #define LLVM_IS_FINAL(Ty) __is_final(Ty)