Questions tagged [clang]

For questions about the clang LLVM compiler front end. For general questions about C, use the C tag.

Usage

This tag should be used for questions specific to clang, an LLVM compiler front end for C-based languages. It should not be used for general questions about C; for those, use the tag.

About

Clang is the LLVM compiler front end for C/C++/Objective-C, which provides fast compiles, useful error and warning messages, an accommodating license and offers an extensible platform for building source level tools.

Why Clang?

The development of a new front-end was started out of a need -- a need for a compiler that allows better diagnostics, better integration with IDEs, a license that is compatible with commercial products, and a nimble compiler that is easy to develop and maintain. All of these were motivations for starting work on a new front-end that could meet these needs.

Current Status

Clang is still under development. Clang is considered to be a production quality C, Objective-C, C++ and Objective-C++ compiler when targeting X86-32, X86-64, and ARM (other targets may have caveats, but are usually easy to fix).

C++ Standards Support

  • C++11 is fully supported in Clang 3.3 and later
  • C++14 is fully supported in Clang 3.4 and later
  • C++17 proposed features are mostly supported in Clang 3.5 and later

Please see the C++ status page for more information.

Related Tags

10121 questions
7
votes
0 answers

Clang optimizes to "ror" instruction in function but not when function is inlined

I found a strange bug in clang optimization. Here is the code: #include unsigned int rot2(unsigned int a, size_t k) { return (a >> k) | (a << (sizeof(unsigned int) * 8 - k)); } int main() { unsigned int x; std::cin >> x; …
Afshin
  • 8,839
  • 1
  • 18
  • 53
7
votes
1 answer

Cannot inspect a std::string variable in lldb

When I try to inspect std::string variable using LLDB, I get "error: summary string parsing error". #include #include int main() { std::string a{"123"}; std::cout << a << std::endl; return 0; } Process 4492…
mukkumayc
  • 130
  • 1
  • 7
7
votes
4 answers

cmake build failed on macos catalina 10.15

I have recently installed macos catalina with Xcode 11.1 and updated cmake, clang and llvm sudo rm -rf /Library/Developer/CommandLineTools xcode-select --install $ cmake --version cmake version 3.15.4 $ which cmake /usr/local/bin/cmake $ clang…
Gajaka
  • 71
  • 1
  • 2
7
votes
1 answer

ADL does not work in constexpr functions (clang only)

The following code compiles with MSVC and gcc, but not with clang. Why is that so? It seems like if ADL would not work if CallFoo () is constexpr. See the comment. template constexpr void CallFoo () // Remove constexpr to fix…
Dr. Gut
  • 2,053
  • 7
  • 26
7
votes
1 answer

Clang - Getting SubstTemplateTypeParm full template information

I am traversing a clang AST, but am having trouble getting the desired information when traversing the type information of a declaration of the AST that contains a clang::SubstTemplateTypeParmType. Given the following minimal input code to clang…
Justin
  • 447
  • 4
  • 10
  • 33
7
votes
1 answer

Why do GCC inserts mfence where Clang dont use it?

Why do GCC and Clang generates so different asm for this code (x86_64, -O3 -std=c++17)? #include int global_var = 0; int foo_seq_cst(int a) { std::atomic ia; ia.store(global_var + a, std::memory_order_seq_cst); return…
kpdev
  • 610
  • 1
  • 7
  • 20
7
votes
1 answer

Is there a reason why Clang does not optimize this code?

Consider this function which I found in this question: void to_bytes(uint64_t const& x, uint8_t* dest) { dest[7] = uint8_t(x >> 8*7); dest[6] = uint8_t(x >> 8*6); dest[5] = uint8_t(x >> 8*5); dest[4] = uint8_t(x >> 8*4); dest[3]…
sebrockm
  • 5,733
  • 2
  • 16
  • 39
7
votes
1 answer

Unable to use aligned `operator new` in a module with Clang

I'm experimenting with Clang "modules" feature, and I'm trying to compile following piece of code: export module a; #include export void *foo() { return ::operator new(1, std::align_val_t(1)); } export int main() {} Try it live When I…
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
7
votes
2 answers

gcc: how to detect bad `bool` usage

Is there some way to detect the bad usage of bool values in code like #include void *foo(void) { return false; } int bar(void) { return true; } Both functions are accepted by gcc (8.3.1) and clang (7.0.1) without any…
ensc
  • 6,704
  • 14
  • 22
7
votes
3 answers

Why does this code break when -O2 or higher is enabled?

I tried to fit an implementation of NSA's SPECK in a 8-bit PIC microcontroller. The free version of their compiler (based on CLANG) won't enable optimizations so I ran out of memory. I tried the "trial" version that enables -O2, -O3 and -Os…
hjf
  • 453
  • 5
  • 16
7
votes
1 answer

Calling methods of temporary objects created using class template argument deduction

I have the following piece of C++17 code that uses class template deduction: template struct Test { T t; Test(T t) : t(t) {} bool check() { return true; } }; template bool check(T t) { …
Nikola Benes
  • 2,372
  • 1
  • 20
  • 33
7
votes
3 answers

MacOS clang via Homebrew broken under Mojave `wchar.h`

Unsurprisingly the new update of OSX Mojave broke my llvm installation in Homebrew, these are the steps I tried: xcode-select --install # Complained, so I installed commandLineTools from here https://developer.apple.com/download/more/ xcode-select…
rausted
  • 951
  • 5
  • 21
7
votes
2 answers

What does a parser for C++ do until it can differentiate between comparisons and template instantiations?

After reading this question I am left wondering what happens (regarding the AST) when major C++ compilers parse code like this: struct foo { void method() { ac; } // a b c may be declared here }; Do they handle it like a GLR parser would…
panoskj
  • 93
  • 5
7
votes
1 answer

Constructor from rvalue reference to base - viable (gcc) or not (clang) - who's right

Had a compliation issue recently, illustrated by this snippet: struct Base { }; template struct A : Base { A(){} A(Base&&) {} }; A foo() { A v; return v; } int main() { auto d = foo(); return…
7
votes
1 answer

OS X: ld: library not found for -lstdc++

I'm trying to wrap a Python lib around a C++ lib and distutils is failing for me on OS X. Here are the relevant lines from my setup.py: if sys.platform.startswith("darwin"): extra_compile_args_setting = ["-std=c++1z", "-stdlib=libc++",…
Jason
  • 531
  • 6
  • 19