clang ++版本:2.9 vim版本:7.3
我写了我的 .clang_comple
--std=c++0x
Run Code Online (Sandbox Code Playgroud)
跟随源代码test.cc:
int main () {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并且clang_complete显示
test.cc|| unknown argument: '--std=c++0x'
Run Code Online (Sandbox Code Playgroud)
在quickfix列表中.
我尝试添加选项
set g:clang_user_options="--std=c++0x"
Run Code Online (Sandbox Code Playgroud)
问题仍然存在.
试图追踪一些clang_complete的代码,但仍然无法解决这个问题.所有其他选项都可以正确处理,但不能--std=c++0x错过任何内容吗?或者做错了什么?
Xcode 4.5中"C++标准库"和"C++语言方言"的"编译器默认值"的值是多少?
我的猜测是libstdc ++和GNU ++ 98,但澄清一下会很好.
使用此Xcode版本创建的项目使用标准C++库的新libc ++实现.libc ++库仅在iOS 5.0及更高版本和OS X 10.7及更高版本上可用.12221787
要在项目的早期版本的iOS和OS X上启用部署,请将C++标准库构建设置设置为libstdc ++(Gnu C++标准库).
我注意到创建一个新项目显式设置了GNU ++ 11和libc ++,但"Compiler Default"可能是其他东西.
我编译这个简单的代码时遇到错误,如果我删除了noexcept,我没有收到错误:
#include<vector>
#include<string>
class Foo
{
public:
protected:
Foo(Foo&&) noexcept = default;
Foo& operator=(Foo&&) noexcept = default;
Foo()
{
}
private:
std::vector<std::string> vectorFoo_;
};
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误,我理解它是在异常规范的实例化中,但我怀疑std :: string不是不可移动构造,...第一个错误让我觉得有一个bug.
在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1中包含的文件中:/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4中包含的文件: /usr/local/bin/../lib/c++/v1/vector:575:67:错误:'std :: __ 1 :: is_nothrow_move_constructible中没有名为'value'的成员,std :: __ 1 :: allocator >>> ' NOEXCEPT(is_nothrow_move_constructible ::值); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^包括/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1:包含在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4中的文件:在文件中包括在/usr/local/bin/../lib/c++/v1/vector:264:/usr/local/bin/../lib/c++/v1/__config:325:34:注意:从宏扩展' NOEXCEPT '定义NOEXCEPT(x)noexcept(x)^包含在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1:/ Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError中的文件. h:29:29:注意:在这里请求'vector'的异常规范实例化std :: vector vectorFoo_; ^在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1中包含的文件:/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4中包含的文件:在/usr/local/bin/../lib/c++/v1/vector:265中包含的文件中:/usr/local/bin/../lib/c++/v1/__bit_reference:15中包含的文件:In文件包含在/usr/local/bin/../lib/c++/v1/algorithm:624:/ usr/local/bin/..Tp> :: type> ^包含在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1中的文件:包含在/ Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics中的文件/TestCompileError.h:4:/usr/local/bin/../lib/c++/v1/vector:575:20:注意:在模板类'std :: _1 :: is_nothrow_move_constructible的实例化中,std :: __ 1: :allocator >>> '在这里请求 NOEXCEPT(is_nothrow_move_constructible ::值); ^在/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.cpp:1中包含的文件:/Users/Mani/Development/Projects/flowOfLife/Graphics/Graphics/TestCompileError.h:4中包含的文件:在/usr/local/bin/../lib/c++/v1/vector:264中包含的文件中:/usr/local/bin/../lib/c++/v1/__config:325:34:注意:扩展从宏' NOEXCEPT '定义 …
使用Xcode分发的LLVM libc ++(对于C++ 11)的string :: find方法实现了什么算法(及其复杂性)?我找不到任何关于它的文档,并且跟随库标题并不是很容易.有人可以帮忙吗?
我不确定如何std::istream::exception 根据标准使用,std::istream::operator>>如果无法将输入读入变量,则抛出异常,例如double.以下代码与clang/libc ++和gcc/libstdc ++有不同的行为:
#include <iostream>
#include <cassert>
int main () {
double foo,bar;
std::istream& is = std::cin;
is.exceptions(std::istream::failbit);
is >> foo; //throws exception as expected with gcc/libstdc++ with input "ASD"
std::cout << foo;
is >> bar;
std::cout << bar;
assert(is); //failed with clang/libc++ after input "ASD"
std::cout << foo << " " << bar << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
根据C++标准,是否is.exceptions(std::istream::failbit);适合operator>>抛出目的?
当我指定了下面的代码不会只编译-stdlib=libc++到clang++:
namespace std {
class mutex;
}
void f(std::mutex &x);
#include <mutex>
void f(std::mutex &x) { }
Run Code Online (Sandbox Code Playgroud)
注意:通过名称查找找到的候选人是'std :: __ 1 :: mutex'
我明白::__1那里有什么,
但在我看来,libc++打破了C++标准定义的API:
它应该可以转发声明,std::mutex因为它应该直接驻留在std,不应该吗?
请注意,编译阶段而不是链接阶段失败.所以我认为我的问题的答案应该是"因为libc ++使用了与GNU libstdc ++不同的ABI ......"
我正在使用Centos平台上的共享库和应用程序[clang ++,llvm3.9.0和libc ++],并且库和应用程序都会重载它们自己的operator new和operator delete.
除1例外,一切正常.在调用std :: string的copy构造函数时总是调用应用程序端的operator new:
这是senario:
std::string str1 ( "A very strange issue on CentOS using clang and libc++" ); //operator new of library side called.
std::string str2(str1); //operator new of application side called. WHY??
Run Code Online (Sandbox Code Playgroud)
对于库侧调用两种情况下的operator delete.
以下是运行以下代码时的日志:
====================================================
operator new in shared library
operator new called Application side
operator delete in shared library
operator delete in shared library
====================================================
Run Code Online (Sandbox Code Playgroud)
共享库侧操作员new和delete:
void * operator new ( size_t len ) throw ( std::bad_alloc …Run Code Online (Sandbox Code Playgroud) 这是关于STL实现处理const副本的区别的问题std::string.我有这么短的测试,它执行2个const副本并打印返回的地址c_str():
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
string a("Hello World!");
const string b(a);
const string c(b);
printf("a: %p = %s\n", a.c_str(), a.c_str());
printf("b: %p = %s\n", b.c_str(), b.c_str());
printf("c: %p = %s\n", c.c_str(), c.c_str());
return c.c_str() == b.c_str();
}
Run Code Online (Sandbox Code Playgroud)
在我的gcc 4.6.2上使用libstdc ++.so.6.0.16 STL所有指针都返回相等.
我可以依靠这种行为吗?
它是便携式还是最近标准中定义的?
这是否适用于当前或未来版本的libstdc ++,libc ++,Microsoft STL,stdcxx(apache.org)?
我一直在使用一些demangling代码,以帮助进行一些调试,而无需使用动态强制转换编写数千行,或者必须实现返回类名的虚函数.
template <class CLASS>
std::string getClassName(CLASS &theObject)
{
int status = 0;
// Convert real name to readable string
char *realName = abi::__cxa_demangle(typeid(theObject).name(), nullptr,
nullptr, &status);
ASSERT(status == 0); // Assert for success
VERIFY(realName, return std::string());
// Return as string + prevent memory leaks!
const std::string result(realName);
free(realName);
return result;
}
Run Code Online (Sandbox Code Playgroud)
这段代码背后的想法很简单,输出我们实际使用的类.虽然在切换到Ubuntu 14.04之后我无法再使用clang和c ++ - 11/c ++ - 14标准进行编译,所以我转而使用libc ++而不是libstdc ++.
在切换到libc ++之后,我注意到当我对'std :: string'进行demangle时它不再输出'std :: string',而是输出:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >
Run Code Online (Sandbox Code Playgroud)
当然这是正确的,因为std :: string是std :: basic_string的typedef.虽然我在libc ++中都可以看到libstdc ++,但是使用typedef以相同的方式定义.所以我真的不明白为什么这个demangling通过切换到libc ++而改变了.
有人知道为什么这是不同的如何获得'std …
对于std::is_literal_type和,这是相同的情况std::is_standard_layout.
std::is_literal_type在libc ++中的实现是
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type
#ifdef _LIBCPP_IS_LITERAL
: public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)>
#else
: integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
is_reference<typename remove_all_extents<_Tp>::type>::value>
#endif
{};
Run Code Online (Sandbox Code Playgroud)
没有_LIBCPP_IS_LITERAL,所以代码将是
template <typename T> struct is_literal_type : integral_constant<bool,
is_scalar<typename remove_all_extents<T>::type>::value or
is_reference<typename remove_all_extents<T>::type>::value> {};
Run Code Online (Sandbox Code Playgroud)
我写了一个演示:
#include <iostream>
using namespace std;
struct s {
int a;
char b;
long c;
};
int main(int argc, char *argv[]) {
cout << boolalpha;
cout << is_scalar_v<typename remove_all_extents<s>::type> << endl;
cout << is_reference_v<typename …Run Code Online (Sandbox Code Playgroud)