clang

Using -fuse-ld=lld with Clang on macOS

元气小坏坏 提交于 2021-01-27 16:43:40
问题 I am using Clang 10 (not AppleClang) on macOS 10.15 and am trying to link with LLD by specifying -fuse-ld=lld in the CMake flags CMAKE_EXE_LINKER_FLAGS . However, I am getting the following error when I try to use LLD: The C++ compiler "/Users/XXX/llvm/bin/clang++" is not able to compile a simple test program. It fails with the following output: ld64.lld: warning: ignoring unknown argument: -platform_version ld64.lld: warning: ignoring unknown argument: -search_paths_first ld64.lld: warning:

Using -fuse-ld=lld with Clang on macOS

£可爱£侵袭症+ 提交于 2021-01-27 16:41:27
问题 I am using Clang 10 (not AppleClang) on macOS 10.15 and am trying to link with LLD by specifying -fuse-ld=lld in the CMake flags CMAKE_EXE_LINKER_FLAGS . However, I am getting the following error when I try to use LLD: The C++ compiler "/Users/XXX/llvm/bin/clang++" is not able to compile a simple test program. It fails with the following output: ld64.lld: warning: ignoring unknown argument: -platform_version ld64.lld: warning: ignoring unknown argument: -search_paths_first ld64.lld: warning:

Can a constexpr c-string used as template parameter be instantiated in a template function?

南楼画角 提交于 2021-01-27 12:49:16
问题 I have been prototyping a library in which I would like to use a c-string value defined locally in a function as a non-type template parameter. In essence, the bare minimum implementation is the following (see on godbolt): #include <cstdio> #include <type_traits> template <char const* C> class compile_string {}; template <typename T> auto foo() { static constexpr char const CSTR[] = "Hello, World!"; return compile_string<CSTR>{}; } int main() { auto shorty = foo<short>(); auto inty = foo<int>

How do I use the clang static analyzer with msbuild on Windows?

空扰寡人 提交于 2021-01-27 10:22:35
问题 The binary windows installer for clang includes scan-build but when you run it with msbuild nothing happens. Even if I do something like: "C:\Program Files\LLVM\bin\scan-build.bat" "C:\Program Files\LLVM\bin\clang.exe" test.cpp I get something like: scan-build: Using 'C:\Program Files\LLVM\bin\clang.exe' for static analysis scan-build: Removed Directory '....' scan-build: No Bugs found Where test.cpp is: void DivideByZero(int z){ if (z == 0) { int x = 1 / z; } } int main() { int *i = nullptr;

How do I use the clang static analyzer with msbuild on Windows?

a 夏天 提交于 2021-01-27 10:19:33
问题 The binary windows installer for clang includes scan-build but when you run it with msbuild nothing happens. Even if I do something like: "C:\Program Files\LLVM\bin\scan-build.bat" "C:\Program Files\LLVM\bin\clang.exe" test.cpp I get something like: scan-build: Using 'C:\Program Files\LLVM\bin\clang.exe' for static analysis scan-build: Removed Directory '....' scan-build: No Bugs found Where test.cpp is: void DivideByZero(int z){ if (z == 0) { int x = 1 / z; } } int main() { int *i = nullptr;

What is the difference between “minimum alignment” and “preferred alignment”?

烂漫一生 提交于 2021-01-27 06:53:32
问题 Recently I observed that on Clang 9.0 alignof and __alignof are returning different values for unsigned long long and the same has been discussed at https://reviews.llvm.org/D54814: Starting in Clang 8.0 and GCC 8.0, alignof and __alignof return different values in same cases. Specifically alignof and _Alignof return the minimum alignment for a type, where as __alignof returns the preferred alignment. I know about type alignment but never came across "minimum alignment" and "preferred

no member named 'str' in 'std::basic_ostream<char>' with gcc and clang, but no problem with msvc

筅森魡賤 提交于 2021-01-27 06:36:03
问题 This code snippet (https://gcc.godbolt.org/z/hKDMxm): #include <iostream> #include <sstream> using namespace std; int main() { auto s = (ostringstream{} << "string").str(); cout << s; return 0; } compiles and runs as expected with msvc, but fails to compile with clang 9.0.0 and gcc 9.2 giving this error message: no member named 'str' in 'std::basic_ostream<char>' . Looking at https://en.cppreference.com/w/cpp/io/basic_ostringstream/str there is clearly str() member of ostringstream . Why

no member named 'str' in 'std::basic_ostream<char>' with gcc and clang, but no problem with msvc

你说的曾经没有我的故事 提交于 2021-01-27 06:35:46
问题 This code snippet (https://gcc.godbolt.org/z/hKDMxm): #include <iostream> #include <sstream> using namespace std; int main() { auto s = (ostringstream{} << "string").str(); cout << s; return 0; } compiles and runs as expected with msvc, but fails to compile with clang 9.0.0 and gcc 9.2 giving this error message: no member named 'str' in 'std::basic_ostream<char>' . Looking at https://en.cppreference.com/w/cpp/io/basic_ostringstream/str there is clearly str() member of ostringstream . Why

Why does clang complain about using variable-length arrays with '-std=c99' flag?

久未见 提交于 2021-01-27 06:35:12
问题 When I compile this experiment code: int main(void) { int foo = 5; char bar[foo]; } with clang and the '-Weverything' or respectively the separate '-Wvla' flag combined with the '-std=c99' flag, I still get the warning: warning: variable length array used [-Wvla] Example here although C99 conform implementations shall, in comparison to later C standards (C11, C18, etc.) - where the VLA-support is optional, support variable length arrays without exception. Why do I still get this warning for

no member named 'str' in 'std::basic_ostream<char>' with gcc and clang, but no problem with msvc

自闭症网瘾萝莉.ら 提交于 2021-01-27 06:35:10
问题 This code snippet (https://gcc.godbolt.org/z/hKDMxm): #include <iostream> #include <sstream> using namespace std; int main() { auto s = (ostringstream{} << "string").str(); cout << s; return 0; } compiles and runs as expected with msvc, but fails to compile with clang 9.0.0 and gcc 9.2 giving this error message: no member named 'str' in 'std::basic_ostream<char>' . Looking at https://en.cppreference.com/w/cpp/io/basic_ostringstream/str there is clearly str() member of ostringstream . Why