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

prohibit inline assembly in g++ (gcc) or clang (llvm)

There are problem-solving sites like topcoder.com, SPOJ. I'd like for similar use-case (people send me C++ program files) to do some restrictions. One of those is: "is not allowed using in-line assembly" How can I enforce such prohibition? Is…
Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88
6
votes
2 answers

Casting an NSError return to a CFErrorRef return

I have a function that returns an NSError object by reference: NSData *foo(NSData *foo, NSError *__autoreleasing *outError); This function uses an API that takes a pointer to storage for a CFErrorRef. I'd like to just pass outError to the…
6
votes
1 answer

std::async in clang 3.0 + libc++ doesn't work?

I just compiled and installed clang+llvm 3.0 on my ubuntu 10.04, and also libc++ from svn. As the status in libc++ shows thread support is complete, I wanted to try std::async. So I follow the example given by Anthony Williams in…
Ralph Zhang
  • 5,015
  • 5
  • 30
  • 40
6
votes
1 answer

malloc attribute takes no arguments

I've created a pair of functions: void destroy_foo(void *ptr); void *create_foo(void); As the names suggest, these function akin to malloc and free. I'd like to use the malloc gcc function attribute to inform the compiler of this relationship so…
Daniel Walker
  • 6,380
  • 5
  • 22
  • 45
6
votes
1 answer

Strange rvalue reference in clang

The following code: #include struct A { A() { std::cout << "()" << std::endl; } A(A&&) { std::cout << "(A&&)" << std::endl; } A(const A&) { std::cout << "(const A&)" << std::endl; } }; A fun (A&& a){ return a; } int…
Kozmar
  • 77
  • 1
6
votes
1 answer

Localizing clang output

Are the clang C compiler's diagnostic messages (warning, errors, etc.) hard-coded, or does it provide a way to specify which language (as opposed to English) to emit them in? Could I provide a custom dictionary for it to use at runtime, without…
Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
6
votes
0 answers

Why does clang do thread-safe init for some globals, but not others?

Consider a global (namespace scope) variable declared using the new inline variable feature in C++ 17: struct something { something(); ~something(); }; inline something global; In Clang 14 on x86 the generated assembly to initialize the…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
6
votes
2 answers

Clang-Tidy slow with dependencies

I am using clang-tidy to lint my code base, but the entire process is very slow. Is there a way to completely ignore header files and not only suppress the warnings? As you can see with this example, a ton of warnings are coming from my project…
6
votes
1 answer

continue in loop is heavily slowing the runtime down in clang

Question I came across a leetcode question gas-station However I found my code is slightly faster if I use if/else rather than if/continue. Edit: after twiddling with the test case. I found the problem is continue It seems that clang is taking…
Louis Go
  • 2,213
  • 2
  • 16
  • 29
6
votes
1 answer

Why is there no warning from -Wfloat-equal when comparing containers of doubles?

If I use the compiler option -Wfloat-equal with GCC or Clang, equality comparisons of float/double values cause a warning. However, when comparing containers (like std::vector or std::tuple) of float or double values, no such warning is…
oliver
  • 6,204
  • 9
  • 46
  • 50
6
votes
1 answer

Can a constructor affect other fields of an enclosing object, or is this a static analysis false positive?

Consider this C++ code: struct SomeStruct { SomeStruct() noexcept; }; //SomeStruct::SomeStruct() noexcept {} class SomeClass { const bool b; const SomeStruct s; public: SomeClass() : b(true) {} operator bool() const { return b;…
6
votes
1 answer

With clang and libstdc++ on Linux, is it currently feasible to use any standard library types in a module interface?

So far it seems to me that including almost any libstdc++ header in a C++ module interface causes compile errors on clang 14.0.0 and the libstdc++ that comes bundled with GCC 11.2.0. I wonder if I am doing something wrong or if this is just not…
Sami Liedes
  • 1,084
  • 8
  • 19
6
votes
1 answer

Why is rv32gc optimising branchless code with branches for RISC-V?

Let's attempt to define a function that returns the maximum of two values x and y. A sufficient condition for these formulas to be valid is that, for signed integers, –2^30 <= x, y <= 2^30 – 1, and for unsigned integers, 0 <= x, y <= 2^31 – 1 (i.e.,…
6
votes
1 answer

Is there a way to tell the clang analyser that a function returns malloc()'ed memory?

I am working on a small library where I don't want to deal with allocation errors everywhere they might pop up, so I've written a wrapper around malloc() that terminates the program (for now) if an error occurs. void *cstr_malloc(size_t size) { …
Thomas Mailund
  • 1,674
  • 10
  • 16
6
votes
1 answer

What's Clang's problem with my code? GCC and MSVC think it's fine

I'm working on an Advent of Code challenge (2021 day 18). Just as a test I tried compiling it on different compilers. While GCC (11.2) and MSVC (19.30) think it's fine, Clang (13.0.0) throws a list of errors. link to compiler…
JHBonarius
  • 10,824
  • 3
  • 22
  • 41
1 2 3
99
100