clang

Redefinition inconsistency in clang between struct and int

大城市里の小女人 提交于 2019-12-22 11:30:52
问题 The following program gives no error when compiling with clang: namespace X { struct i {}; } namespace Y { using X::i; struct i {}; } int main() {} Let's use int instead of struct, then we get: namespace X { int i; } namespace Y { using X::i; int i; } int main() {} This program gives a redefinition error when compiling with clang. The only difference between the programs is the kind of entity used (struct or int), but one compiles without errors and the other gives a redefinition error. Does

Pragma message in Clang?

守給你的承諾、 提交于 2019-12-22 10:58:24
问题 What's Clang's equivalent to #pragma message as used in GCC and MSVC? 回答1: I've brought this up on the Clang mailing list, and it's in discussion now. It's subsequently been implemented as a warning, and hopefully soon it will be behave as it does in other compilers. 回答2: #pragma message has been implemented recently - too recently for the current release (2.7), but it should be included in the forthcoming 2.8. 来源: https://stackoverflow.com/questions/3796894/pragma-message-in-clang

stack-protect equivalent in clang compiler?

六眼飞鱼酱① 提交于 2019-12-22 10:54:31
问题 Most of the mature compilers appear to have good support for stack variable clobbers. GCC: -fstack-protector xlC: -qstackprotect intel: -fstackprotector windows: /RTC For clang I've found -fsanitize=safe-stack, but it doesn't support shared libraries, which makes it pretty much useless for me. It looks like that sanitizer is implemented as an add-on? Does anybody know if clang has any sort of alternate (built-in?) anti stack-smashing support that doesn't have the no shared library restriction

How to extract compilation args for each compilation unit in a vcxproj?

冷暖自知 提交于 2019-12-22 10:52:46
问题 I'm trying to get the compilation args for each compilation unit so I can create the "compilation_commands.json" for my vcxproj that can be used with clang's libTooling. The libTooling tutorial suggests using a CompilationDatabase to provide the compilation args for all the cpp files in a project. The tutorial shows that CMake can generate the compilation_commands.json for CMake based projects. Since clang can be put into "MSVC mode" via clang.exe --driver-mode=cl or clang-cl.exe my thought

Clang 3.1 + libc++ Compile Error

邮差的信 提交于 2019-12-22 09:39:59
问题 I've built and installed (under the prefix ~/alt ) LLVM-Clang trunk (23 apr 2012) successfully using GCC-4.6 on Ubuntu 12.04 and in turn libc++ using this Clang-build. When I want to use it I have to supply both -lc++ and -libstdc++ as follows /home/per/alt/bin/clang -x c++ -I/home/per/alt/include/v1 -L/home/per/alt/lib -std=gnu++0x -g -Wall ~/f.cpp -lm -lc++ -lstdc++ -lpthread -o f to compile f.cpp containing #include <iostream> using std::cout; using std::endl; int main(int argc, const char

Are “NSString * __unused aString” and “NSString __unused * aString” equivalent?

无人久伴 提交于 2019-12-22 09:39:41
问题 Are NSString * __unused aString and NSString __unused * aString equivalent, when they are variable declarations? Are - (void)aMethod:(NSString * __unused)aString and - (void)aMethod:(NSString __unused *)aString equivalent, when they are Objective-C method parameter declarations? If the answer is "yes", what form should I prefer as correct? Both forms in both cases seem to work identically when enabling/disabling GCC_WARN_UNUSED_PARAMETER and GCC_WARN_UNUSED_VARIABLE directives. I didn't find

How is “__builtin_va_list” implemented?

六眼飞鱼酱① 提交于 2019-12-22 08:11:53
问题 I want to delve into the implementation of function "printf" in C on macOS. "printf" uses the <stdarg.h> header file. I open the <stdarg.h> file and find that va_list is just a macro. So, I am really curious about how the __builtin_va_list is implemented? I know it is compiler-specific. Where can I find the definition of the __builtin_va_list ? Should I download the source code of clang compiler? 回答1: So, I am really curious about how the __builtin_va_list is implemented? __builtin_va_list is

clang 3.3/Xcode & libc++: std::getline does not read data after calling ifstream::clear()

≯℡__Kan透↙ 提交于 2019-12-22 07:06:40
问题 The following program demonstrates an inconsistency in std::getline behavior between libc++ and libstdc++ (using clang3.3). The program opens the file testfile, reads it until eof, then clears the error bits using ifstream::clear and tries to read from the same filehandle again to see if new data was appended to the file. #include <fstream> #include <iostream> #include <unistd.h> using namespace std; int main() { ifstream* file = new ifstream("testfile"); if ( ! file->is_open() ) { cout <<

Link binary with static library in xcconfig

时间秒杀一切 提交于 2019-12-22 06:58:57
问题 I have an Xcode project that is essentially a single app that gets built into several almost identical targets. I have moved nearly all build configuration settings in central places, but I cannot figure out how to move linking against a static library (libMantle.a) to the xcconfig. I have tried the -framework and -l flags, like I'm using for various other libraries, but they don't work. Is there a way to get .a files out of the Link Binary with Libraries pane, so I don't need to keep all the

how to use standard library with C++ modules? (eg: `import std.io`)

对着背影说爱祢 提交于 2019-12-22 06:06:13
问题 The basic example given in How do I use C++ modules in Clang? works for me but doesn't import the standard library (eg via import std.stdio; ); after going over http://clang.llvm.org/docs/Modules.html it wasn't clear how to use the standard library in a C++ module, eg: // foo.cppm: export module foo; // works: #include <stdio.h> // none of these work: import std.stdio; import std.io; import std; export void test_foo(){ printf("hello world\n"); } this gives an error: clang++ -std=c++17