[cfe-dev] Fwd: [libc++] Is libc++ compatible with previous c++ language standard implementation
Zeson Wu via cfe-dev
cfe-dev at lists.llvm.org
Wed Mar 7 18:37:37 PST 2018
Sorry to not reply to all. So FYI.
---------- Forwarded message ----------
From: Zeson Wu <westion717 at gmail.com>
Date: 2018-03-08 10:32 GMT+08:00
Subject: Re: [cfe-dev] [libc++] Is libc++ compatible with previous c++
language standard implementation
To: alan snape <alansnape3058 at gmail.com>
What I mean above for libc++ is the source/header of libc++ library.
I can not find the prototype of (1). I just find
#if _LIBCPP_STD_VER > 11
> explicit vector(size_type __n, const allocator_type& __a);
> #endif
> vector(size_type __n, const_reference __x);
> vector(size_type __n, const_reference __x, const allocator_type& __a);
Is the implementation legal and to be suitable for all language level among
03, 11 and 14? But how to explain the case I showed before? The output of
the case is different by gcc with option -std=c++11 and -std=c++03, but
it's same by clang.
#include <iostream>
> #include <vector>
>
> struct T
> {
> bool flag;
> T() : flag(false) {}
> T(const T&) : flag(true) {}
> };
>
>
> int main()
> {
> std::vector<T> test(1);
> bool is_cpp11 = !test[0].flag;
>
> std::cout << is_cpp11 << std::endl ;
> }
2018-03-08 10:09 GMT+08:00 alan snape <alansnape3058 at gmail.com>:
> As a template class, it is impossible to find the `std::vector` class in
> libc++. When writing a template class, all the code need during
> compile-time should be provided in the header file; and when compiling with
> a template class/function, the template parameter will be replaced with the
> concrete type/argument. As you can see, this is just a compile-time process
> rather than a link-time process, much less the libc++.
>
> explicit vector( size_type count, const T& value = T(), const Allocator&
>> alloc = Allocator()); (until C++11) *(1)*
>> explicit vector( size_type count );(since C++11) (until C++14) *(2)*
>>
>> If I use vector<T> a(1), which one will be chosen with different c++ std
>> command option, such as -std=c++03, -std=c++11? Actually, I can not find
>> the (1) version in libc++ source.
>>
> Just as what I mentioned above, the answer is it depends. If you compile
> your code under standard C++11, (2) will be used; if you use previous
> standard, (1) will be used. (Also, it depends on the argument you provided,
> but the header file will deal with it.)
>
>
>> In my option, both two functions should be implemented and guarded by
>> related language level macro, but I can not find in libc++ source. So
>> libc++ is not compatible with previous c++ language standard implementation?
>>
> So, it is not weird to find nothing about that.
>
--
Zeson
--
Zeson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180308/2f398947/attachment.html>
More information about the cfe-dev
mailing list