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

Can enum member be the size of an array in ANSI-C?

I need to allocate an array according to how many elements the enum have. I did the following: enum { A, B, C, LAST }; char buf[LAST]; That works fine,even with -ansi -pedantic flags. But I'm not sure if it's a GCC or clang(wich supports most,if…
Jack
  • 16,276
  • 55
  • 159
  • 284
7
votes
1 answer

Xcode 4.5 and OpenMP with Clang (Apple LLVM) uses only one core

We are using Xcode 4.5 on a C++11 project where we use OpenMP to speed up our computation: #pragma omp parallel for for (uint x=1; x
Pascal
  • 831
  • 2
  • 11
  • 24
7
votes
1 answer

Simple Hello World in Objective-C with clang and gnustep does not compile

System: 64bit Ubuntu Lucid GNUStep clang/LLVM test.m #import int main(int argc, char * argv[]){ NSLog(@"Hello world!\n"); return 0; } compile command line: clang -fobjc-gc -I…
SwiftMango
  • 15,092
  • 13
  • 71
  • 136
7
votes
2 answers

Storage of the "hidden array" behind initializer_list

In the C++11 standard there is a note regarding the array backing the uniform initialisation that states: The implementation is free to allocate the array in read-only memory if an explicit array with the same initializer could be so…
Shane
  • 757
  • 3
  • 11
7
votes
2 answers

Using the C preprocessor to determine current scope?

I am developing an application in C / Objective-C (No C++ please, I already have a solution there), and I came across an interesting use case. Because clang does not support nested functions, my original approach will not work: #define…
7
votes
1 answer

Catching derived exceptions types fails on Clang/MacOS X

I have a C++ library which I'm trying to get running on Mac OS X with Clang. The library consists of a DLL and a Unit-Test executable. It compiles fine with GCC and MSVC, with GCC, I use the following settings: The library is compiled with…
Anteru
  • 19,042
  • 12
  • 77
  • 121
7
votes
1 answer

Is this a compiler bug or it's my code?

Here is a sample code: #include #include #include #include #include using std::cout; using std::endl; std::size_t const BUF_SIZE(1000); std::ostream& operator<<(std::ostream& os, std::tm const&…
Reza Toghraee
  • 1,603
  • 1
  • 14
  • 21
7
votes
1 answer

How is an empty class and an empty struct compiled?

Does the C++ standard dictate the compilation layout of the class and struct? How are they compiled differently especially if they are empty?
unj2
  • 52,135
  • 87
  • 247
  • 375
7
votes
3 answers

How to reduce the time of clang_complete search through boost

I like using clang with vim. The one problem that I always have is that whenever I include boost, clang goes through boost library every time I put "." after a an object name. It takes 5-10 seconds. Since I don't make changes to boost headers, is…
kirill_igum
  • 3,953
  • 5
  • 47
  • 73
7
votes
2 answers

Decide in Clang if the visited CXXRecordDecl is class, struct or union

I use Clang to build up an AST from C++ source code and RecursiveASTVisitor to traverse the tree. I would like to decide at a visited declaration of record if it is class, struct or union. I have an overridden function…
bmolnar
  • 171
  • 8
6
votes
3 answers

Clang error: ambiguous conversion for static_cast

I have the following piece of code: typedef int AliasB; typedef unsigned short AliasA; class Alias { public: explicit Alias(int someInt) { } }; // (*) !! below breaks the conversion path via AliasA !! //typedef Alias AliasA; class…
celavek
  • 5,575
  • 6
  • 41
  • 69
6
votes
1 answer

Move semantics in MS C++ vs Clang

After doing some experimentation with move semantics with an array type I created, I am wondering why Microsoft's C++ compiler calls the move constructor when returning from a method by value whilst the Clang compiler elides the copy all…
Blair Davidson
  • 901
  • 12
  • 35
6
votes
4 answers

Using Clang Static Analyzer from within Xcode

Since there is no Xcode script variable for "current project directory," how can you create a script menu item to run the Clang Static Analyzer on your current project from Xcode?
mmc
  • 17,354
  • 2
  • 34
  • 52
6
votes
1 answer

How to get location of variable name in clang::VarDecl

I'm using clang 3.0 library for some analysis of C/C++ code, and I need to get location of variable declaration, I tried this code: clang::VarDecl * vd = ...; clang::SourceManager & srcMgr = ...; clang::SourceRange loc =…
Alexey
  • 938
  • 5
  • 13
6
votes
1 answer

Dynamic instrumentation with Clang

I'm trying to get up to speed on using Clang by doing a bit of dynamic code instrumentation with C (and maybe C++) where I take a source file and generate an instrumented output. I'd like to add a function call at the beginning of any block and…