clang

No warning for implicit cast of bool to floating type?

泪湿孤枕 提交于 2021-02-07 13:18:28
问题 Looks like this snippet compiles in clang without warning, even with -Weverything: double x; ... if (fabs(x > 1.0)) { ... } Am I missing something? Or do the compiler and C++ standard think that casting bool to double is something that makes sense? 回答1: This is a consequence of making bool an integral type. According to C++ standard, section 3.9.1.6 Values of type bool are either true or false (Note: There are no signed , unsigned , short , or long bool types or values. — end note) Values of

Template argument deduction: which compiler is right here?

为君一笑 提交于 2021-02-07 12:17:29
问题 Consider the following code: template<int N> class Vector { }; #include <array> template<int N> void doWork(const Vector<N>&, const std::array<int,N>&) { } int main() { std::array<int,3> arr; Vector<3> vec; doWork(vec,arr); } Here Vector represents a class which is defined in a third-party library, and std::array is known to take its element count as std::size_t . I've tried compiling this with clang-3.6 and g++-5.1. Clang worked without any complaint, while g++ gives the following error:

Template argument deduction: which compiler is right here?

左心房为你撑大大i 提交于 2021-02-07 12:15:31
问题 Consider the following code: template<int N> class Vector { }; #include <array> template<int N> void doWork(const Vector<N>&, const std::array<int,N>&) { } int main() { std::array<int,3> arr; Vector<3> vec; doWork(vec,arr); } Here Vector represents a class which is defined in a third-party library, and std::array is known to take its element count as std::size_t . I've tried compiling this with clang-3.6 and g++-5.1. Clang worked without any complaint, while g++ gives the following error:

Should decltype(foo(1)) instantiate the constexpr function template foo?

…衆ロ難τιáo~ 提交于 2021-02-07 12:04:49
问题 The following code compiles with with gcc and MSVC, but fails using clang I tested with clang-3.5 and current trunk). template <typename T> constexpr auto wrong = false; template <typename T> constexpr auto foo(const T t) -> int { static_assert(wrong<T>, ""); return {}; } using F = decltype(foo(1)); int main() {} clang instantiates the function body and stumbles over the static_assert . gcc and MSVC just look at the function declaration and ignore the static_assert in the body. If you remove

gcc doesn't accept pack expansion in default template argument

不想你离开。 提交于 2021-02-07 06:34:31
问题 Following code is compiled successfully with clang, but gcc fails: struct fn { template <typename ... Args> static constexpr bool call (Args ... ) { return true; } }; template <typename ... T> static constexpr bool f = false; template <typename ... Ts, bool F = fn::call(f<Ts> ...)> void hoge () {} int main () {} gcc 5.1.0 (-Wall -Wextra -std=c++14 -pedantic) says prog.cc:10:52: error: expansion pattern 'f<Ts>' contains no argument packs template <typename ... Ts, bool F = fn::call(f<Ts> ...)>

How to find memory leaks with Clang

一世执手 提交于 2021-02-07 05:47:06
问题 I have installed Clang in my machine (ubuntu) in order to find memory leaks in my C code. I wrote a sample code in order to check the working of it which is as follows: /* File: hello.c for leak detection */ #include <stdio.h> #include <stdlib.h> void *x; int main() { x = malloc(2); x = 0; // Memory leak return 0; } I found some options in internet to compile like $ scan-build clang --analyze hello.c and $ scan-build clang -fsanitize=address hello.c But none of them are showing any signs of

Does clang offer anything similar to GCC 6.x's function multi-versioning (target_clones)?

扶醉桌前 提交于 2021-02-07 05:46:19
问题 I've read this LWN article with great interest. Executive summary: GCC 6.x supports something called function multi-versioning which builds multiple versions of the same function, optimized for different instruction sets. Let's say you have a machine with AVX2 support and one without. It's possible to run the same binary on both, with function foo() existing in two versions, one of which uses AVX2 instructions. The function with the AVX2 instructions are, however, only called if the CPU

clang can't parse my .h file standalone

一曲冷凌霜 提交于 2021-02-07 03:00:53
问题 I'm using python binding of libclang but I think this problem is caused by libclang not by python binding. I have a header object.h #ifndef OBJECT_H #define OBJECT_H class Object { public: int run(); }; #endif And a implementation object.cpp #include "object.h" int Object::run() { int a = 0; return a*a; } If I visit AST of the translation unit of object.h , the last AST node is VAR_DECL class Object and that's it. It won't visit public:... part. If I use clang to check syntax directly is

浅谈编译过程

谁说我不能喝 提交于 2021-02-06 14:29:53
女主宣言 笔者前端时间在运行一个组内 Swift 项目的时候,发现编译时间比较长。所以查了部分优化项目编译时间的资料(当然还有部分原因是自己的电脑配置比较低)。并打算记录2篇文章。第一篇文章主要记录关于编译过程的内容,第二篇文章记录笔者在优化 Swift 项目编译时间的一点尝试。 本文是第一篇关于编译过程的文章。笔者将本文中介绍编译过程相关的内容,本文会按如下几个部分展开。 PS:丰富的一线技术、多元化的表现形式,尽在“360云计算”,点关注哦! 编译相关名词解释; 1.1 编译器 1.2 编译器架构 1.3 GCC 1.4 Clang 1.5 LLVM 编译过程简单了解; 2.1 词法分析; 2.2 语法分析; 2.3 语义分析; 2.4 生成中间代码; 2.5 优化中间代码; 2.6 生成目标代码; 用具体命令代码简单分析编译过程;首先名词解释部分,笔者会介绍编译器、GCC、LLVM相关内容。 一、 名词解释 1. 编译器 编译器不是硬件,是可以把源程序编译为目标程序的计算机程序。 编译器 (compiler)是一种计算机程序,它会将某种编程语言写成的源代码(原始语言)转换成另一种编程语言(目标语言)。引自维基百科编译器 编译器功能示意图 2. 编译器架构 编译器架构: 2.1 Frontend:前端 词法分析、语法分析、语义分析、生成中间代码(汇编指令) 2.2

Is a c++11 variadic function template overload with a dependent type ambiguous?

匆匆过客 提交于 2021-02-06 11:06:58
问题 The following code is a textbook example of a recursive variadic function overload. In both clang and GCC, it compiles cleanly, and main returns 36 (as expected): template <typename T> int add(T val) { return val; } template <typename FirstTypeT, typename... RestT> int add(FirstTypeT first_value, RestT... rest) { return first_value + add<RestT...>(rest...); } int main(void) { return add(12, 12, 12); } However, here is a slight modification. It uses a dependent type in the template definition