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
2 answers

Why does "empty" loop cause bus error when compiling C program with clang -O2 on macOS?

I'm on macOS High Sierra. $ uname -v Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 I have the following synthesized program. void nop1() { for (;;); } void nop2() { while (1); } void nop3()…
Karl Marklund
  • 485
  • 1
  • 4
  • 10
7
votes
1 answer

How can you add a new keyword to clang, a keyword that would be treated as main?

How can a new keyword be added to clang? The new keyword should be a function qualifier. Where would the declaration part go? Thanks.
marius c
  • 73
  • 1
  • 3
7
votes
2 answers

Why GCC does not report uninitialized variable?

#include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); map v; int i; int t; while (cin >> i) { v[i] = t++; } auto mi = i; auto mt = t; for (const auto p…
Bernardo Sulzbach
  • 1,293
  • 10
  • 26
7
votes
1 answer

Why does the compiler write a member variable to memory for each iteration of this loop?

The first version does an optimisation by moving a value from memory to a local variable. The second version does not. I was expecting the compiler might choose to do the localValue optimisation here anyway and not read and write the value from…
JCx
  • 2,689
  • 22
  • 32
7
votes
1 answer

No compiler warning for obvious segfault

I am surprised this compiles without any warning: int main() { *"abc" = '\0'; } with gcc main.c -Wall -Wextra and clang main.c -Weverything. Why is there no warning for this ? Is there any way this could not raise a segmentation fault ?
Bilow
  • 2,194
  • 1
  • 19
  • 34
7
votes
3 answers

"Include What You Use"

I read about tool called "Include What You Use" which can help clean superfluous includes from source code. I understood that there is a version for compiler LLVM (Clang) and version for GCC. My questions are: Why is this tool compiler-dependent…
Or Shemesh
  • 71
  • 1
  • 2
7
votes
1 answer

Clang can't compile programs using the header anymore

I'm using clang Version 4.0.0 on my system running ArchLinux, it always worked fine, but recently I can't compile programs that use certain STL headers anymore! Details: Output of clang --version: clang version 4.0.0 (tags/RELEASE_400/final) …
nshct
  • 1,197
  • 9
  • 29
7
votes
1 answer

Why does clang emit these warnings?

The clang compiler emit warnings for the snippet below, as can be seen here. clang++ -std=c++14 -O0 -Wall -pedantic -pthread main.cpp && ./a.out main.cpp:1:18: warning: braces around scalar initializer [-Wbraced-scalar-init] void point(int = {1},…
João Afonso
  • 1,934
  • 13
  • 19
7
votes
1 answer

cannot specify -o when generating multiple output files [C error]

I have a question about make file using gcc, below is my code in makefile. I got cannot specify -o when generating multiple output files error, but I just cant see where the problem is. Can someone point out my mistakes?…
Total_Noob
  • 103
  • 1
  • 5
7
votes
1 answer

using result of constexpr function as a template parameter (clang vs gcc)

Please take a look at the code below, sorry that is a bit lengthy, but I did my best to reproduce the problem with a minimum example (there is also a live copy of it). There I basically have a metafunction which returns the size of string literal,…
Slava
  • 1,528
  • 1
  • 15
  • 23
7
votes
2 answers

Surprising behavior of literal type at runtime

I'm a bit perplexed by the behavior of this code compiled with clang 3.9: struct A { constexpr A() = default; A(const A&) = delete; constexpr A(A&&) {} A& operator =(const A&) = delete; constexpr A& operator =(A&&) { return…
Oleg Bogdanov
  • 1,712
  • 13
  • 19
7
votes
3 answers

clang++ warning: "warning: unknown warning option '-Wno-maybe-uninitialized'"

Having installed LLVM on Ubuntu 16.04 using the command: sudo apt-get install clang llvm I get the following error when compiling: nlykkei@nlykkei-VirtualBox:~$ clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs` -o…
Shuzheng
  • 11,288
  • 20
  • 88
  • 186
7
votes
2 answers

Why do lambda functions drop deduced return type reference by default?

In C++14, why do lambda functions with a deduced return type drop references from the return type by default? IIUC, since C++14 lambda functions with a deduced return type (without an explicit trailing return type) have a return type of auto, which…
Danra
  • 9,546
  • 5
  • 59
  • 117
7
votes
1 answer

How does clang's uint24_t work? Can I use it outside clang/LLVM?

Being a GCC user, I've just noticed clang supports a uint24_t type (it's in their stdint.h anyway). How does that work? I mean, is it supported purely internally, as a language extension, or is it implemented like a C++ class would, with some…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
7
votes
1 answer

Should non-capturing generic lambdas decay to function pointers?

Consider the following code: int main() { auto l = [](auto){}; void(*p)(int) = l; } It works just fine both with GCC and clang. Let's consider the following slightly modified version: int main() { auto l = [](auto...){}; …
skypjack
  • 49,335
  • 19
  • 95
  • 187