标签: clang++

铿锵"你好,世界!" Windows中的链接错误

我刚下载了CLang源代码,使用CMake创建了一个Visual C++ 10 IDE工作区,并构建了Visual C++ 10.0(express)中的所有内容.

现在我在hello world上遇到了一堆链接器错误:

d:\dev\test> type con >foo.cpp
#include <iostream>
using namespace std;
int main() { cout << "Hello, cling-clong world!" << endl; }
^Z

d:\dev\test> clang++ foo.cpp
foo-839435.o : error LNK2019: unresolved external symbol __ZSt4cout referenced in function _main
foo-839435.o : error LNK2019: unresolved external symbol __ZdlPv referenced in function __ZNSt14error_categoryD0Ev
foo-839435.o : error LNK2019: unresolved external symbol __ZSt18uncaught_exceptionv referenced in function __ZNSo6sentry
D2Ev
foo-839435.o : error LNK2019: unresolved external symbol ___cxa_rethrow referenced in function …

c++ std clang linker-errors clang++

11
推荐指数
1
解决办法
7130
查看次数

如何检测我的代码是否使用-fno-exceptions进行编译?

我正在编写一个C++库,我想让我的API抛出无效参数的异常,但是在编译代码时依赖于assert -fno-exceptions.

如果允许我使用异常处理,有没有办法在编译时检测?请注意,我正在编写一个只有头的库,所以我没有configure阶段,我无法访问构建系统,只需在命令行上定义一个宏(我不想增加负担给用户).

由于标准没有"-fno-exceptions"的任何概念,当然解决方案可能依赖于编译器.在这种情况下,我对使用g ++和clang ++的解决方案感兴趣,其他编译器对于这个项目并不重要.

非常感谢你

c++ g++ clang++

11
推荐指数
1
解决办法
1102
查看次数

什么是与Xcode捆绑在一起的LLVM版本?

在键入时,clang --version我们获得了有关它所构建的LLVM版本的信息:

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Run Code Online (Sandbox Code Playgroud)

但是现在使用Xcode 7我们只得到以下内容:

Apple LLVM version 7.0.0 (clang-700.0.72)
Run Code Online (Sandbox Code Playgroud)

llvm clang llvm-clang clang++ xcode7

11
推荐指数
1
解决办法
5115
查看次数

Rcpp和默认的C++编译器

我对Rcpp有一些奇怪的麻烦 - 它使用了不可预测的C++编译器.这个问题有点类似于这个问题.
我在OSX上,我有2个编译器 - 默认clang和openmp clang-omp支持.我也有以下~/.R/Makevars文件(我设置clang-omp为默认编译器):

CC = clang-omp
CXX = clang-omp ++
CFLAGS + = -O3 -Wall -pipe -pedantic -std = gnu99
CXXFLAGS + = -O3 -Wall -pipe -Wno-unused -pedantic -fopenmp

问题是,我正在开发的软件包编译而clang++不是clang-omp++.我也尝试过(作为实验来解决问题)更改包src/Makevars和设置CXX=clang-omp++以及修改后的$R_HOME/etc/Makeconf CXX条目CXX = clang-omp++.没有运气 - 它仍然可以编译clang++.不知道为什么会这样.

这里也是小的可重现的(来自控制台R和来自Rstudio)的例子(不知道它是否与上面的问题有关).假设2个非常相似的cpp函数:
1.

#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
  return x * 2;
} …
Run Code Online (Sandbox Code Playgroud)

macos r rcpp clang++

11
推荐指数
1
解决办法
4349
查看次数

为什么GCC优化不适用于valarrays?

这是一个使用valarrays的简单c ++程序:

#include <iostream>
#include <valarray>

int main() {
    using ratios_t = std::valarray<float>;

    ratios_t a{0.5, 1, 2};
    const auto& res ( ratios_t::value_type(256) / a );
    for(const auto& r : ratios_t{res})
        std::cout << r << " " << std::endl;
    return 0;  
}
Run Code Online (Sandbox Code Playgroud)

如果我编译并运行它像这样:

g++ -O0 main.cpp && ./a.out
Run Code Online (Sandbox Code Playgroud)

输出如预期:

512 256 128 
Run Code Online (Sandbox Code Playgroud)

但是,如果我编译并运行它:

g++ -O3 main.cpp && ./a.out
Run Code Online (Sandbox Code Playgroud)

输出是:

0 0 0 
Run Code Online (Sandbox Code Playgroud)

如果我使用-O1优化参数,也会发生相同

GCC版本是(最新的Archlinux):

$ g++ --version
g++ (GCC) 6.1.1 20160707
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试使用clang,两者都可以

clang++ -std=gnu++14 -O0 main.cpp && ./a.out
Run Code Online (Sandbox Code Playgroud)

和 …

c++ gcc g++ clang++

11
推荐指数
1
解决办法
397
查看次数

使用别名模板时,无法将"std :: unique_ptr"分配给clang中的基类

以下代码在gcc 4.9.3和clang 3.7.1上编译并运行得很好

// std::unique_ptr
#include <memory>

// Template class for template-template arguments
template <typename Real>
struct Bar {};

// Base class 
template <typename T,template <typename> class XX>
struct Base {};

// Derived class that operates only on Bar 
template <typename Real>
struct Derived : public Base <Real,Bar> {};

// Holds the unique_ptr 
template <typename T,template <typename> class XX>
struct Foo {
    std::unique_ptr <Base <T,XX>> foo;
};

// Create an alias template 
template <typename Real>
using Buz = Bar <Real>; …
Run Code Online (Sandbox Code Playgroud)

c++ clang clang++ c++14

11
推荐指数
1
解决办法
579
查看次数

引用在封闭函数中声明的本地绑定

采取以下代码:

#include <array>

int main() {
    auto [a, unused] = [] {
        return std::array<int, 2>{42, 24};
    }();

    [&] {
        return a * 15;
    }();

    (void) unused;
}
Run Code Online (Sandbox Code Playgroud)

不用担心unused变量,我只想对数组进行解构。

使用最新的GCC和MSVC可以很好地编译代码,但是Clang 拒绝编译。更改lambda的捕获列表不会更改任何内容。有趣的是,a在捕获列表中显式设置会引发错误a is not a variable

我很确定这是一个错误,但是我想问一下,主要是因为AFAIK a是对数组第一个元素的引用(main在这种情况下,生存期扩展到了范围),而不仅仅是一个int,请纠正我错误。

编辑

你可以从其他的问题看,问题是,aunused变量(是的,锵是正确的!),但参考的名字,不能用lambda表达式被捕获。不过,如果您确实需要这样的东西,可以为lambda使用局部变量,如下所示:

#include <array>

int main() {
    auto [a, unused] = [] {
        return std::array<int, 2>{42, 24};
    }();

    [&, a = a] …
Run Code Online (Sandbox Code Playgroud)

c++ clang++ c++17

11
推荐指数
0
解决办法
1773
查看次数

SFINAE:“enable_if 不能用于禁用此声明”

为什么我不能enable_if在以下上下文中使用?

我想检测我的模板化对象是否具有成员函数 notify_exit

template <typename Queue>
class MyQueue
{
   public:
    auto notify_exit() -> typename std::enable_if<
            has_member_function_notify_exit<Queue, void>::value,
            void
        >::type;

    Queue queue_a;
};
Run Code Online (Sandbox Code Playgroud)

初始化为:

MyQueue<std::queue<int>> queue_a;
Run Code Online (Sandbox Code Playgroud)

我不断收到(clang 6):

example.cpp:33:17: error: failed requirement 'has_member_function_notify_exit<queue<int, deque<int, allocator<int> > >, void>::value';
      'enable_if' cannot be used to disable this declaration
            has_member_function_notify_exit<Queue, void>::value,
Run Code Online (Sandbox Code Playgroud)

或(g++ 5.4):

In instantiation of 'class MyQueue<std::queue<int> >':
33:35:   required from here
22:14: error: no type named 'type' in 'struct std::enable_if<false, void>'
Run Code Online (Sandbox Code Playgroud)

我尝试了很多不同的东西,但不知道为什么我不能enable_if用来禁用这个功能。这不正是enable_if为了什么吗?

我在这里放了一个完整的例子 …

c++ sfinae c++11 clang++

11
推荐指数
2
解决办法
3734
查看次数

自动模板参数:g ++ 7.3 vs clang ++ 6.0:哪个编译器正确?

两个编译器为此代码示例生成不同的结果.Clang生成两种不同的类型.G ++使用相同的类型fufi.哪一个符合标准?

#include <iostream>

template< auto IVAL>
struct foo {
    decltype(IVAL) x = -IVAL;
};

int main()
{
    foo<10u> fu;
    foo<10> fi;
    std::cout << fi.x << " " << fu.x << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

g ++ - 7.3输出:

4294967286 4294967286

clang-6.0输出:

-10 4294967286

c++ g++ clang++ c++17

10
推荐指数
1
解决办法
344
查看次数

在 Clang 中基于每个函数启用快速数学?

fast-mathGCC 提供了一种使用 属性有选择地优化函数/代码段的方法 。有没有办法在 Clang 中使用 pragmas/attributes 启用相同的功能?我了解 Clang 提供了一些 编译指示 来指定浮点标志。然而,这些编译指示均未启用fast-math.

PS:之前有人问过类似的问题,但在 Clang 的上下文中没有得到回答。

c++ clang++ c++17

10
推荐指数
1
解决办法
1103
查看次数

标签 统计

clang++ ×10

c++ ×8

c++17 ×3

clang ×3

g++ ×3

c++11 ×1

c++14 ×1

gcc ×1

linker-errors ×1

llvm ×1

llvm-clang ×1

macos ×1

r ×1

rcpp ×1

sfinae ×1

std ×1

xcode7 ×1