问题标签 [libc++]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
239 浏览

xcode - 使用来自 libc++ 的 std::list 的对象层次结构(错误?)

我想我在 libc++ 列表实现中发现了一个错误。在 xcode 中使用某些构建设置时,以下代码将产生编译器错误(字段具有不完整的类型 'foo'):

设置如下:

XCode 版本: 4.4.1
C++ 语言方言: C++11 或 GNU++11
C++ 标准库:具有 C++ 扩展的 LLVM C++ 标准库 (libc++11)

使用 GCC 的 libstdc++ 将解决该错误。
不使用 C++11 方言将解决该错误。
使用向量而不是列表将解决该错误。

我认为这是列表实现中的一个错误,但我不确定。
原谅我的无知,但我不知道我应该怎么做才能解决这个问题。
在我的项目中切换到矢量不是一个选项,我绝对需要 C++11 功能。这也包括 shared_ptr,但使用 GCC 时缺少标头。除此之外,苹果似乎不再提供新版本的 GCC。

如果有人可以重新创建此问题,我将不胜感激,也许使用来自 libc++ 的新标头。

另外,如果更新 LLVM/libc++ 可以解决这个问题,你推荐吗?

0 投票
1 回答
956 浏览

c++ - 在 Xcode 4.4 中调试 libc++ 的问题

当我尝试在 c++ 上调试列表迭代时遇到问题。

我做了一个简单的测试应用程序:

在调试时,当我在标有箭头的行上时,当我跨过时,它开始从 c++ 文件中插入代码:'list'。我必须跨过 15 次,直到它最终到达 for 语句中的代码。

这个问题只发生在 Xcode 4.4 中。在 Xcode 4.3 中,调试工作完美。

这里有一些不同的场景有不同的结果:

  1. 使用 LLVM GCC 4.2 作为编译器 → 它工作正常。
  2. 使用 Apple LLVM 编译器 4.0 并为 C++ 标准库设置 libstdc++(GNU C++ 标准库)→ 它工作正常。
  3. Apple LLVM 编译器 4.0 并为 C++ 标准库设置 libc++(支持 C++11 的 LLVM C++ 标准库)→ 出现问题。

在我正在进行的项目中,我们使用的是 Apple LLVM 编译器 4.0 和 libc++(支持 C++11 的 LLVM C++ 标准库),所以我需要为场景 3 解决这个问题)。

有谁知道会发生什么以及是否有解决办法?

0 投票
2 回答
2078 浏览

c++ - Customising std::shared_ptr or boost::shared_ptr to throw an exception on NULL dereference

I have a few projects that use boost::shared_ptr or std::shared_ptr extensively (I can convert to either implementation soon enough, if there is a good answer to this question for one, but not the other). The Boost implementation uses Boost.Assert to avoid returning in the case of encountering an empty (NULL) pointer in operator* or operator-> at runtime; while the libc++ implementation seems to lack any check.

While of course the validity of a shared_ptr should be checked before use, a large, mixed-paradigm codebase leads me to want to try an exception-throwing variation; as most of the code is relatively exception-aware and will at most fail to a high-level but resumable state, rather than std::terminate() or segfault.

How should I best customise these accessors while maintaining the robustness of shared_ptr? It seems that encapsulating shared_ptr in a throwing_shared_ptr may be the best option, but I'm wary of breaking the magic. Am I best off copying the Boost source and just changing the ASSERTs to an appropriate throw statement?


The actual type name used everywhere for the appropriate smart_ptr<T> type is a typedef expanded from a macro; i.e. ForwardDeclarePtr(Class) expands to something like:

Everything passes, takes, or stores a ClassPtr - so I can replace the underlying type pretty freely; and I suspect this alleviates the potential slicing/hiding issue.

0 投票
1 回答
21431 浏览

c++ - 使用带有 clang++ -stdlib=libc++ 的 libstdc++ 编译库

我在 Mac OS X (10.8.2) 下使用 C++ 工作,最近我想出了使用 C++11 功能的需求,这些功能可以通过使用 libc++ stdlib 的 clang++ 编译器获得。但是,我还需要使用一些针对 libstdc++(来自 MacPorts)编译和链接的遗留库。

这样做时,我得到了链接错误,因为使用例如 的遗留库的标头std::string需要针对std::__1::basic_string(即 libc++ 的实现std::string)而不是实现来解析std::basic_string

有没有办法在开发中混合这两个库(例如,通过使用一些预处理器标志?)

0 投票
0 回答
530 浏览

c++ - 使用 clang 和 libc++ 中止 boost 单元测试框架

我在用:

SLES 11 x86_64

Boost 1.51.0使用以下内容编译:./b2 toolset=clang cxxflags="-stdlib=libc++ -std=c++11" linkflags="-stdlib=libc++"

来自svn的clang (大约两个弱者)

来自 svn 的libc++ (几乎是最新的)

测试在最后被中止(SIGABORT):

这是一个非常有趣的回溯:

当它想打印出测试结果时它失败了。当所有测试用例都通过时,也会发生同样的情况。可以看出,在 std::ostream 的销毁过程中不知何故出现了异常。奇怪的是,std::uncaught_exception 不是来自 libc++ 内联命名空间 (__1)。

你们有没有遇到过类似的问题?有什么问题?

更新:libcxx 中可能存在的错误:http://llvm.org/bugs/show_bug.cgi?id= 13669

0 投票
1 回答
10929 浏览

c++ - 在 Xcode 4.5 中,“C++ 标准库”和“C++ 语言方言”的“编译器默认值”是什么?

Xcode 4.5 中“C++ 标准库”和“C++ 语言方言”的“编译器默认值”是什么值?

我的猜测是 libstdc++ 和 GNU++98,但最好能澄清一下。

来自Xcode 4.5 发行说明

使用此 Xcode 版本创建的项目使用标准 C++ 库的新 libc++ 实现。libc++ 库仅适用于 iOS 5.0 及更高版本以及 OS X 10.7 及更高版本。12221787

要在项目中的早期版本的 iOS 和 OS X 上启用部署,请将 C++ 标准库构建设置设置为 libstdc++(Gnu C++ 标准库)。

我注意到创建一个新项目明确设置了 GNU++11 和 libc++,但“编译器默认值”可能是别的东西。

0 投票
1 回答
388 浏览

c++ - libc++ 中可能存在的错误?

下面的代码没有用clang 3.1编译,使用libc++(不知道版本,目前Xcode自带的)。它适用于其他标准库。我的代码中是否有错误,或者这是 libc++ 中的错误?

我看到的错误是<utility>

我试图进一步隔离它,但这是我发现的最小示例。有趣的是,当我在第二张地图中替换为时(当我在第一张地图中替换string为int时):intintstring

0 投票
1 回答
2278 浏览

c++ - std::map 是否要求比较器的 operator() 为 const?

在 OS X 10.8 上使用 libc++ 时,以下代码无法使用 XCode 4.5 的 clang++ 编译:

错误:

broken.cpp:11:8:注意:候选函数不可行:“this”参数的类型为“const FooComparator”,但方法未标记为 const bool operator()(const Foo& left, const Foo& right) {

如果我关闭 libc++ 并使用 libstdc++ 构建,那么一切都很好。显然,我可以通过将 FooComparator::operator() 设为 const 来解决这个问题,但我想了解这是否是 libc++ 过于严格的问题,或者标准(C++03 和 C++11 ) 实际上确实要求比较器的 operator() 是 const (在这种情况下,它与 libstdc++ 一起工作的事实是一个幸运的意外)。

0 投票
1 回答
793 浏览

linux - ubuntu 11.04下的clang ++链接问题与libc ++

我在ubuntu 11.04下编译了libc++,做了软链接

在 /usr/lib 下,也是 stl 头文件的软链接

在 /usr/include/c++ 下

当我编译一个小的多线程 hello world 示例时,编译返回以下错误:

0 投票
1 回答
5550 浏览

c++ - 使用 Google Test、Clang 和 libc++ 构建测试时遇到问题

我尝试使用以下 CMake 配置构建 Google Test:

构建显示 CMake 选择了正确的编译器,但我的编译器标志没有通过:

最终目标是我希望使用 Clang 和 libc++ 构建的项目能够使用 Google Test 构建测试。这意味着我也需要使用 libc++ 构建的 Google Test。