clang

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

倖福魔咒の 提交于 2021-02-06 11:02:01
问题 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

C++ code segfaults when compiled -O with Apple's LLVM compiler, but not with g++ -7.2.0

我的未来我决定 提交于 2021-02-06 10:20:10
问题 Update: I've created an even more M, but still CVE that reproduces the crash. Summary: removed all use of the Bool* bools_ field in Base class (but it still must be defined or the crash does not happen). Also removed Base::Initialize() and the virtual method Rule from Base and its descendants. New MCVE is attached. I've managed to create an MCVE for this code and posted it below. Some descriptive details: the code uses virtual base and derived classes, and certain derived classes that are

gcc 10.1: weird behavior with clang-tidy (clion) and precompiled headers (cmake)

匆匆过客 提交于 2021-02-05 10:28:38
问题 I have had problems with my IDE since an update to GCC 10.1 a few days ago. I use CLion, which uses clang-tidy as linter. I also use the newly introduced command target_precompiled_headers from CMake to use PCH for my project. Unfortunately I get weird linter warning and error messages: That's how I include the header file for my pch in my CMakeLists.txt : target_precompile_headers(Peach PRIVATE ${PROJECT_SOURCE_DIR}/Src/peach_pch.h) Strangely enough, my program compiles perfectly. So the

gcc 10.1: weird behavior with clang-tidy (clion) and precompiled headers (cmake)

蓝咒 提交于 2021-02-05 10:26:35
问题 I have had problems with my IDE since an update to GCC 10.1 a few days ago. I use CLion, which uses clang-tidy as linter. I also use the newly introduced command target_precompiled_headers from CMake to use PCH for my project. Unfortunately I get weird linter warning and error messages: That's how I include the header file for my pch in my CMakeLists.txt : target_precompile_headers(Peach PRIVATE ${PROJECT_SOURCE_DIR}/Src/peach_pch.h) Strangely enough, my program compiles perfectly. So the

Clang AST Interpretation

独自空忆成欢 提交于 2021-02-05 09:28:16
问题 I am trying to interpret parts of the Clang AST you can see in the picture below. In short I am trying to do is to check if two variables are the same at different program points. After inspecting the AST, I noticed that the only commonality between the AST sections are the sections circled in blue. Can anyone help me as to what these hex numbers correspond to in the AST? I understand that the first block corresponds to a Variable Declaration and the second block corresponds to a Expression.

cmake detect which library libc++ or libstdc++ is configured to be used against g++ or clang++

╄→гoц情女王★ 提交于 2021-02-05 06:43:05
问题 I wrote an CMakeLists.txt to build a project with either g++ or clang++ . To catch as many as possible bugs I use both libc++ with -D_LIBCPP_DEBUG2=2 (for clang++ ) and libstdc++ with -D_GLIBCXX_DEBUG (for both g++ and clang++ ). set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -fno-inline -DDEBUG=1 -march=x86-64 -mtune=generic") #[[ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_LIBCPP_DEBUG2=2") elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") set

Narrowing int to bool in SFINAE, different output between gcc and clang

烂漫一生 提交于 2021-02-04 22:12:04
问题 Consider the following example: template<int i> struct nice_type; template<class T> struct is_nice : std::false_type {}; template<int i> struct is_nice< nice_type<i> > : std::integral_constant<int, i> {}; template<class T, class = void> struct pick { typedef std::integral_constant<int, -1> type; }; template<class T> struct pick<T, typename std::enable_if< is_nice<T>::value >::type > { typedef std::integral_constant<int, is_nice<T>::value > type; }; int main() { std::cout << pick<int>::type:

Excluding internal headers from framework umbrella header

喜夏-厌秋 提交于 2021-02-04 13:45:25
问题 While trying to begin using Swift in a framework (including turning on module support), I started getting messages like this: [snip]/<module-includes>:1:1: Umbrella header for module 'PressKit' does not include header 'NPKBaseAppearance.h' The headers in question (there are about ten of them) are not listed in PressKit.h, but with good reason—they include internal or rarely-used classes and categories that I don't want to expose to most users of my framework. (Some of them I'd like to expose

基于Mac下使用c++11

落爺英雄遲暮 提交于 2021-02-02 12:05:02
项目场景:基于Mac下使用c++11 问题描述: 在Mac在使用的编译器是clang如果直接使用clang在遇到c++11的时候他会有warning警告甚至有例如__gcd()函数,pair等报错的情况,如果在clang编译器下添加c++11呢?我查询了很多csdn都没有一劳永逸的做法(我尝试过改变很多设置参数但是还是于事无补),所以我只能每次在编译之前设置echo。 下图是在vscode下的报错结果 下图是在终端上运行的结果 解决方案: 每次在编译的时候输入以下内容(一句一句的输入哦 vscode或者终端都可以) echo "alias g++='g++ -std=c++11'" >> ~/.bashrc source ~/.bashrc 结果: 在终端上的运行结果如下(不会再有warning或者error了) 在vscode上运行的结果如下 ps:此处的的waring可以不用担心,因为+运算符的优先级是高于位运算的,所以这个warning可以忽略。 如果大家有什么一劳永逸的方法麻烦评论一下谢谢! 来源: oschina 链接: https://my.oschina.net/u/4328825/blog/4941428

小白学PYTHON时最容易犯的6个错误

十年热恋 提交于 2021-02-01 02:44:30
最近又在跟之前的同学一起学习python,一起进步,发现很多测试同学在初学python的时候很容易犯一些错误,特意总结了一下。其实这些错误不仅是在学python时会碰到,在学习其他语言的时候也同样会碰到。 错误1:缩进 python是强制缩进的语言,很多同学在初次接触python时可能会不习惯,缩进老是犯错。比如 Python 2.7.12 (default, Sep 17 2016, 13:47:40) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> good = "ok" File "<stdin>", line 1 good = "ok" ^ IndentationError: unexpected indent 这种错误一般会提示IndentationError,最后根据错误所在行一般都能够很快的解决问题。 错误2: 中英文符号 很多初学者是分不清中英文符号的区别的,比如说:这是英文的冒号,而:这个冒号是中文的。乍一看长得差不多,但实际上确实不同的字符。比如 >>> x = 0>>> if x == 1: File "<stdin>",