Clang 3.1 and C++11 support status - c++

From clang's C++11 support status website, http://clang.llvm.org/cxx_status.html , it says, "Initializer List" and "Lambda Expression" are all supported starting from version 3.1.
However, using LLVM/Clang trunk (3.2), compiling against initializer list and lambda expression will yield error messages.
Does anyone know if Clang >3.1 supports those features?

By default, clang++ will not enable the C++11 features - you have to pass an additional flag during compilation.
clang++ -std=c++11 [input files...]
Or
# enables some additional C++11 extensions GCC has
clang++ -std=gnu++11 [input files...]
Additionally, you can switch between using libstdc++ and Clang's own libc++, which are different implementations of the C++ standard library. libc++ in some cases might have a better implementation of the C++11 standard than your existing libstdc++ library.
# uses clang's C++ library in C++98 mode
clang++ -stdlib=libc++ [input] # uses clang's C++ library
# uses clang's C++ library and enables C++11 mode
clang++ -stdlib=libc++ -std=c++11 [input]
The latter is important if you're using Clang in an environment with an outdated version of libstdc++ (like Mac OSX), but note that the two C++ libraries are not compatible with each other, so you would have to rebuild any dependencies against libc++ if you were to use that.

The page at http://clang.llvm.org/cxx_status.html is confusing at best. Currently, the released 3.1 version does not support initializer lists or lambdas (so I've switched back to GCC 4.8 for the time being).
You can always check clang support for features using the __has__feature macro, according to the instructions here:
http://clang.llvm.org/docs/LanguageExtensions.html#checking_language_features
For example, __has_feature(cxx_generalized_initializers) or __has_feature(cxx_lambdas) will return true if those features are available and enabled.
Personally, I'm expecting those features to be ready by clang 4.0, which is expected to be released with the next Xcode (likely June 2012).
-- Edited to clarify the versions I've been testing -- clearly, clang versioning is more complex than I had realized.

Related

format library not included (using G++ -std=c++2a) [duplicate]

If it doesn't, do you know what compiler or version will?
See cppreference/format.
It's 2023 Now! Cheers!
GCC 13, CLANG 14 and MSVC 16.10/VS 2019 all have the {fmt} based std::format available in respective standard libraries.
Hopefully we'll have C++23 std::print available soon.
See Compiler support here :-
gcc (libstdc++)
clang (libc++)
msvc (vc++)
Does gcc support C++20 std::format?
Not yet!
There's no compiler support yet, not even gcc 11. See Text formatting in Library features.
Compiler support for C++20 library features
As of today (November 15, 2022), GCC 12.2 does not support this feature. Or rather, its standard library implementation doesn't support it (cause it's a library feature, not the compiler-one).
NOTE: The feature is mentioned as implemented in GCC 13.0 (link)
You can try Clang 14.0.0 and upward for now, but note following:
In libc++ of Clang 14.0.0 std::format support added but: "The paper is implemented but still marked as an incomplete feature. Not yet implemented LWG-issues will cause API and ABI breakage" (link)
In libc++ of Clang 15.0.0 and later, this feature can be enabled with the -fexperimental-library compiler flag (link)
Also you can try MSVC 16.10 and upward. Support of std::format is mentioned as complete.
Standard library current status can be seen here:
GCC: libstdc++
Clang: libc++
MSVC: msvc-170
Now libstdc++ has implemented it!
https://gcc.gnu.org/pipermail/libstdc++/2022-November/054991.html
GCC 13 has added support for std::format. According to cppreference, as of GCC 13, no gaps remain in its C++20 support (in both the core language and the standard library).
This bugzilla ticket notes that some C++23 extensions to std::format have not yet been implemented.
GCC 13 can be expected around April 2023.
The GCC trunk installation on compiler explorer includes std::format support.

Mac M1 C++20: Missing std::convertible_to and std::forward_iterator concepts

I'm trying to compile a quite big school project on a Mac M1 and I'm facing some missing concept problem.
The project has not really been thought for arm compilation, but I'm trying to see if it would be possible.
I passed the first step: the configure script runs as expected and generate a Makefile as expected.
The problem appears during compilation of some files of the project: clang seems to be missing some standard library concepts (c++20). I have 2 errors about missing concepts: std::convertible_to and std::forward_iterator.
After some research, I found that the apple version of clang for M1 chips does not fully implements all the c++20 features and I think it is the problem I'm facing.
Is there any other compiler for the AArch64 architecture that implements more features of the modern versions of C++ or should I give up now ?
After some research, I found that the apple version of clang for M1 chips does not fully implements all the c++20 features and I think it is the problem I'm facing.
You may want to try Clang from Homebrew(or compile one by yourself). And you can check its implemented features on Clang's offical website.
❯ clang++ --version
Homebrew clang version 13.0.0
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
❯ cat test.cpp
#include <concepts>
#include <iterator>
static_assert(std::convertible_to<char, int>);
static_assert(std::forward_iterator<char*>);
❯ clang++ -std=c++20 -c test.cpp
❯
Please remember that C++20 is still quite fresh and it is very big change to the standard (IMO bigger change then C++11). As a result support of some C++20 features is limited and varies between compilers. It will take couple years to have descent support of this standard.
Here is site which lists current status of C++20 features, for different compilers:
Compiler support for C++20 - cppreference.com
C++20 feature
Paper(s)
GCC libstdc++
Clang libc++
MSVC STL
Apple Clang
Concepts library
P0898R3
10
13
19.23*
12.0.0* (partial)
So as you can see, Apple clang is a bit behind in supporting concepts library.

C++14 TS functionality and GCC 4.8

I would like to try some of the new features that will make it to the C++2014 revision like std::make_unique and the std::filesystem functionnalities. I use ubuntu 14.04 and GCC/G++ 4.8 (with libstdc++-4.8-dev installed), and the flag -std=c++1y set. But there is no std::make_unique when including <tr1/memory>, and no <experimental/...> headers.
What do I need to do to be able to use some of those new features ?
Thanks !
<tr1/memory> is not a C++14 standard header. You simply want <memory>. Same for <dynarray>.
However, neither are supported in GCC 4.8. You need to upgrade to GCC 4.9 or clang 5.
The GCC compiler support status for C++1y can be checked on the Language Features status page, and the library support on the Library Support status page.

C++11 functionality with MinGW

I try to use emplace() function for an unordered_map and compiler says that no such function exists.
I put -std=c+11 and it says cc1plus.exe: error: unrecognized command line option '-std=c+11'
Can i somehow use C++11 functionality with mingw?
From the GCC documentation
C++0x was the working name of a new ISO C++ standard, which was then
released in 2011 as C++11 and introduces a host of new features into
the standard C++ language and library. This project seeks to implement
new C++11 features in GCC and to make it one of the first compilers to
bring C++11 to C++ programmers.
C++11 features are available as part of the "mainline" GCC compiler in
the trunk of GCC's Subversion repository and in GCC 4.3 and later. To
enable C++0x support, add the command-line parameter -std=c++0x to
your g++ command line. Or, to enable GNU extensions in addition to
C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7
and later support -std=c++11 and -std=gnu++11 as well.
So, for gcc 4.3 through 4.6 use -std=c++0x, for later version use -std=c++11. Library support for map::emplace was added in gcc 4.8

How can I use C++ 11 features in Clang?

How can I use the latest C++ 11 features in Clang? What (sub)set of features is supported?
You will need clang 3.3 to use the most relevant feature set from C++ 11. Read C++ Support in Clang for the complete list of up-to-date supported features. Clang 3.3 is claimed to be C++11 feature complete.
Clang's command line is gcc-compatible so you have to enable C++11 support via the followinf command-line switch
-std=c++11
There is also a bunch of post-C++11 features (like decltype(auto), member initializers and aggregates) that are supported by Clang 3.3. Use this command line switch to enable them
-std=c++1y
Here is the always up to date list of features supported by clang:
http://clang.llvm.org/cxx_status.html
To activate C++11, you have to add -std=c++11 in your clang calls, like for gcc.
If you use an IDE that is clang-aware or gcc-aware, there is a specific project settings option available to do that.