clang

C++ init-list: using non-initialized members to initialize others gives no warning

隐身守侯 提交于 2020-01-13 08:27:41
问题 Neither g++ (4.4 and 4.6) nor clang++ (3.2) nor coverity, with -Wall and -Wextra (+ some others) or -Weverything respectively gives me a warning for the following code snippet: class B { char *t2; char *t; public: B() : t2(t), t(new char[100]) {} }; I would at least expect a small warning about the usage of uninitialized (member-) variables. Is there something I'm missing? Is this a wanted "no-warning"-scenario. I have (now had) at least one bug in my software which was hard to find. EDIT :

PIC error compiling ACE with Clang

♀尐吖头ヾ 提交于 2020-01-13 06:45:08
问题 I'm tring to compile some ACE lib within my project with PCH support and including only sources that i need I'm on ubuntu 16.04 and i need to use clang but i've this error: error: PIC level differs in PCH file vs. current file I've prepared a MVCE, you need clang installed ofc, then just run following commands: git clone https://github.com/Yehonal/ace-clang-test.git cd ace-clang-test mkdir build cd build cmake -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CC_COMPILER=/usr/bin/clang -DCMAKE_CXX

C++ libclang: Retrieving cursor from CXSourceLocation returning wrong cursor?

泄露秘密 提交于 2020-01-13 03:56:50
问题 I am currently writing a simple clone detector using libclang with C++. The program stores cursors using a struct, containing a pointer to the translation unit and the CXSourceLocation gained from calling clang_getCursorLocation(cursor). typedef struct { CXTranslationUnit* tu; CXSourceLocation srcLoc; } t_cursorLocation; For the sake of this error, the child visitor function visits each node and creates a struct from each cursor. With a struct of type t_cursorLocation, I wrote this function

How to Compile C++14 code for Android?

时光毁灭记忆、已成空白 提交于 2020-01-12 14:30:50
问题 Is it possible to compile C++14 source code for Android with ndk10d? I've tried both g++ and clang compilers but it seems that -std=c++14 -std=c++1y flags do not work. If I use c++_static as my APP_STL, i get the following error: User/someone/Software/Android/android-ndk-r10d/platforms/android-17/arch-arm/usr/include/locale.h:55:1: error: empty struct has size 0 in C, size 1 in C++ Edit: I am using Mac OSX 10.10.4 with Xcode 6.3.2 (able to compile C++14 for iOS). 回答1: I use android-ndk-r12b

ARC equivalent of autorelease?

风流意气都作罢 提交于 2020-01-12 13:34:49
问题 If I have this code, + (MyCustomClass*) myCustomClass { return [[[MyCustomClass alloc] init] autorelease]; } This code guarantees the returning object is autoreleased. What's the equivalent of this in ARC? 回答1: There is no equivalent in ARC, as you don't need to do it yourself. it will happen behind the scenes and you are not allowed to do it your self. You simply use - + (MyCustomClass*) myCustomClass { return [[MyCustomClass alloc] init]; } I suggest you to watch the ARC introduction in the

llvm/clang compile error with Memory exhausted

孤者浪人 提交于 2020-01-12 04:10:36
问题 I am trying to build the latest llvm/clang code on my ubuntu 14.04 vm, which has 2GB memory. What I did is a normal configure/make procedure, without any parameters to these two commands. at last, I have the following error: llvm[4]: Linking Debug+Asserts executable clang /usr/bin/ld: failed to set dynamic section sizes: Memory exhausted collect2: error: ld returned 1 exit status make[4]: *** [/home/alex/Downloads/llvm_build/Debug+Asserts/bin/clang] Error 1 make[4]: Leaving directory /home

__attribute__ ((deprecated)) does not work on objective-c protocol methods?

℡╲_俬逩灬. 提交于 2020-01-12 03:21:09
问题 I need to deprecate a single method in objective-c protocol. On normal class/instance methods I add __attribute__ ((deprecated)); after declaration. It seems, that it does not work on protocol methods. If I mark them deprecated and use them somewhere the project compiles OK, without expected deprecation warning. Is it a flaw in Apple LLVM 3.1, or am I doing something wrong? 回答1: Although the answers here provide some very good information, they are outdated. Starting with Xcode 5.0 and LLVM 5

bit-field in overload resolution for template

佐手、 提交于 2020-01-11 09:51:31
问题 Anyone knows why the first program compiles but second one doesn't? The only difference is that the first one uses normal function but the second one uses template function. Why the overload resolution behaves differently on bitfield for template and non-template function? Please refer to paragraphs in standard when answering. Thanks. a.cpp struct X { int x : 20; int y : 12; }; void f(const int& x) {} void f(int&& x) {} int main() { X x; f(x.x); } b.cpp struct X { int x : 20; int y : 12; };

bit-field in overload resolution for template

瘦欲@ 提交于 2020-01-11 09:51:27
问题 Anyone knows why the first program compiles but second one doesn't? The only difference is that the first one uses normal function but the second one uses template function. Why the overload resolution behaves differently on bitfield for template and non-template function? Please refer to paragraphs in standard when answering. Thanks. a.cpp struct X { int x : 20; int y : 12; }; void f(const int& x) {} void f(int&& x) {} int main() { X x; f(x.x); } b.cpp struct X { int x : 20; int y : 12; };

templated friend function lookup

∥☆過路亽.° 提交于 2020-01-11 09:25:08
问题 The following simple code compiles fine class A { int x[3]; public: A() { x[0]=1; x[1]=2; x[2]=3; } friend int const&at(A const&a, unsigned i) noexcept { return a.x[i]; } friend int foo(A const&a, unsigned i) noexcept { int tmp = at(a,i); return tmp*tmp; } }; but if the friends are made templates class A { int x[3]; public: A() { x[0]=1; x[1]=2; x[2]=3; } template<unsigned I> friend int const&at(A const&a) noexcept { static_assert(I<3,"array boundary exceeded"); return a.x[I]; } template