标签: clang++

替换失败有时是错误的吗?

以下代码snipplet尝试实现'std :: is_constructible <A,int>':

#include <type_traits>

struct A { 
  // A(int);
};

template< typename T >
struct cstr_int
{
  static int mi;

  template< typename C >
  static typename std::enable_if< 
    std::is_same< decltype( T( mi ) ), T >::value, char >::type choose( C * );
  static long choose( ... );

  enum { value = ( sizeof( decltype( choose( & mi ) ) ) == 1 ) };
};

bool const b1 = cstr_int< A >::value;
Run Code Online (Sandbox Code Playgroud)

使用g ++这很好用; 使用clang ++打印以下错误:

tmp/sfinae04.cc:14:29: error: no …
Run Code Online (Sandbox Code Playgroud)

c++ sfinae clang++

2
推荐指数
1
解决办法
833
查看次数

无法声明没有名称的类模板

错误:

“无法声明没有名称的类模板”

由 clang++ 给出以下文件“foo.cpp”:

#ifndef foo
#define foo

template <class T>
struct foo {
private:
    const T t;
};

#endif
Run Code Online (Sandbox Code Playgroud)

命令行输入及错误:

me@computer$ clang++ -c foo.cpp
foo.cpp:5:1: error: cannot declare a class template with no name
Run Code Online (Sandbox Code Playgroud)

c++ c-preprocessor clang++

2
推荐指数
1
解决办法
949
查看次数

我们不能混合使用g ++和clang ++编译的对象(或库)?至少在Mac上?

功能如

MyFunction(std::string) 
Run Code Online (Sandbox Code Playgroud)

在Mac上用g ++编译为:

__Z6MyFuncSs
Run Code Online (Sandbox Code Playgroud)

解构为:

MyFunction(std::string)
Run Code Online (Sandbox Code Playgroud)

用clang ++编译时,它是:

__Z6MyFuncNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
Run Code Online (Sandbox Code Playgroud)

解构为:

MyFunc(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)
Run Code Online (Sandbox Code Playgroud)

在Linux上没有相同的问题
任何人都知道为什么?

c++ compilation g++ clang++

2
推荐指数
1
解决办法
655
查看次数

为什么这个程序在Clang或GCC下不能正常运行?

我正在尝试运行CPPReference的regex_search示例:

#include <iostream>
#include <string>
#include <regex>

int main()
{
    std::string lines[] = {"Roses are #ff0000",
                           "violets are #0000ff",
                           "all of my base are belong to you"};

    std::regex color_regex("#([a-f0-9]{2})"
                        "([a-f0-9]{2})"
                        "([a-f0-9]{2})");

    for (const auto &line : lines) {
        std::cout << line << ": " 
                  << std::regex_search(line, color_regex) << '\n';
    }   

    std::smatch color_match;
    for (const auto &line : lines) {
        std::regex_search(line, color_match, color_regex);
        std::cout << "matches for '" << line << "'\n";
        for (size_t i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

c++ regex clang++

2
推荐指数
1
解决办法
315
查看次数

使用 clang 强制对 constexpr 进行编译时评估

为了constexpr在编译时强制对函数求值,我应该能够将它的返回值赋给一个constexpr变量。

constexpr bool const_d_ref(const double& v) { return false; }

int main() {
  constexpr double dd = 0.0;
  constexpr bool cb = const_d_ref(dd);
}
Run Code Online (Sandbox Code Playgroud)

这似乎适用于g++clang++

为了对constexpr消费者隐藏,我将实际的函数定义移到 中namespace detail,创建一个新函数,该函数将返回值分配给一个constexpr变量并返回它。

namespace detail {
constexpr bool const_d_ref(const double& v) { return false; }
}
constexpr bool const_d_ref(const double& v) {
  constexpr bool b = detail::const_d_ref(v);
  return b;
}
int main() {
  constexpr double dd = 0.0;
  bool b = …
Run Code Online (Sandbox Code Playgroud)

c++ g++ constexpr clang++ c++14

2
推荐指数
1
解决办法
1539
查看次数

在 Ubuntu 16.04 下运行协程示例给出“'experimental/coroutine' file not find”

查看 clang-5.0发行说明,它说“ C++ 协程 TS已落地”,并建议查看此示例以开始使用。我显然可以在线运行该示例,因此我决定在我的 Ubuntu Server 16.04 Xenial 机器上尝试一下。

从干净的安装中,我刚刚尝试过

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
sudo apt-get update
sudo apt-get install -y clang-5.0 libc++-dev
Run Code Online (Sandbox Code Playgroud)

并直奔

clang++-5.0 -Wall -Wextra -std=gnu++2a "-fcoroutines-ts" "-stdlib=libc++" -o test.out test.cpp 
Run Code Online (Sandbox Code Playgroud)

(是上述示例test.cpp的复制和粘贴

然而,我只是得到

coroutines.cpp:2:10: fatal error: 'experimental/coroutine' file not found
#include <experimental/coroutine>
Run Code Online (Sandbox Code Playgroud)

所以我可以想象我缺少一些东西,无论是安装还是在编译标志中。我尝试在网上查找,但找不到任何有用的东西。

我究竟做错了什么?

c++ coroutine clang++

2
推荐指数
1
解决办法
5254
查看次数

为什么LLVM项目使用GCC Headers

我正在查看一个使用 Clang 构建的项目,但它需要 GCC 标头。

为什么一个项目需要 Clang 和 GCC 头文件?

gcc llvm clang llvm-clang clang++

2
推荐指数
1
解决办法
753
查看次数

如何在 autoconf 中为 clang 检查支持编译标志

我们可以使用以下方法检查对特定编译器标志的支持autoconf

AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
Run Code Online (Sandbox Code Playgroud)

这些检查返回 true 但clang不支持它们。

AX_CHECK_COMPILE_FLAG([-Woverride-init])
AX_CHECK_COMPILE_FLAG([-Wformat-truncation])
Run Code Online (Sandbox Code Playgroud)

如何在autoconffor 中检查支持编译标志clang

我改变了我的编译器

export CC=/usr/bin/clang-6.0 
export CXX=/usr/bin/clang++-6.0 
Run Code Online (Sandbox Code Playgroud)

如果回显到脚本$CC$CXX,一切正常。

链接到 configure.ac

c c++ autoconf clang clang++

2
推荐指数
1
解决办法
860
查看次数

使用CLANG内联汇编创建C ++预增量操作

我正在尝试b = ++a;与内联汇编等效,但是执行代码后,变量中却得到了奇怪的值。我正在使用clang ++(与g ++兼容)来编译内联汇编。这是到目前为止我得到的:

#include <iostream>

using std::endl;
using std::cout;

int main()
{
    uint64_t a = 0;
    uint64_t b = 0;

    asm volatile(
    "pushq %%rbp;"
    "movq %%rsp, %%rbp;"
    "movl $0, -4(%%rbp);"
    "movl $0, -8(%%rbp);"
    "addq $1, -4(%%rbp);"
    "mov -4(%%rbp), %%rax;"
    "mov %%rax, -8(%%rbp);"
    "mov -4(%%rbp), %0;"
    "mov -8(%%rbp), %1;"
    "movq %%rbp, %%rsp;"
    "popq %%rbp"
    :"=r" (a), "=r" (b)
    :
    :"%rax", "%rbp", "%rsp"
    );
    cout << "a = " << a << ", b = " << b …
Run Code Online (Sandbox Code Playgroud)

c++ x86 x86-64 inline-assembly clang++

2
推荐指数
1
解决办法
93
查看次数

我在 Clang 和 GCC 中发现了错误吗?

主.cpp:

#include <iostream>

struct Cls {
    static void some_method() {
        std::cout << __FILE__ << ": " << __LINE__ << std::endl;
    }
};

extern void call_some_method();

void never_caled() {
    Cls::some_method();  // (1)
}

int main() {
    call_some_method();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

cls.cpp:

#include <iostream>

struct Cls {
    static void some_method() {
        std::cout << __FILE__ << ": " << __LINE__ << std::endl;
    }
};

void call_some_method() {
    Cls::some_method();
}
Run Code Online (Sandbox Code Playgroud)

当 (1) 被注释时, call_some_method() 将 "/home/maxim/CLionProjects/bug/cls.cpp: 5" 写入 std::cout。

当 (1) 未注释时, call_some_method() 将 …

c++ gcc clang++

2
推荐指数
1
解决办法
80
查看次数