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

Weird return value in strcmp

While checking the return value of strcmp function, I found some strange behavior in gcc. Here's my code: #include #include char str0[] = "hello world!"; char str1[] = "Hello world!"; int main() { printf("%d\n",…
fips197
  • 137
  • 7
7
votes
0 answers

Implicit conversions and different behavior of compilers

Motivated by this question1, I created the following code: struct X { X(int) {} }; struct Y { operator X() { return X{1}; } operator int() { return 1; } }; int main() { X x(Y{}); } Live demo with error messages. This…
Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
7
votes
2 answers

SFINAE method completely disables base class's template method in clang

#include #include struct B { template::value>* = nullptr> void foo(T) { std::cout<<"B::foo"<
wanghan02
  • 1,227
  • 7
  • 14
7
votes
1 answer

clang compiled program throws std::bad_any_cast during std::any_cast

I'm working on an application where I use std::any. Recently I've discovered that when I compile it with clang I'm getting bad_any_cast exception on one of the std::any_casts. I'm sure I'm casting to right type. I've added some dumps of…
Michał Walenciak
  • 4,257
  • 4
  • 33
  • 61
7
votes
1 answer

Setup Clang on Travis CI for C++17

I have a small C++17 project for which I want to setup Travis CI. Since it is C++17 it requires modern compilers; I settled for gcc-7 and clang-6. While the gcc build compiles and links just fine, I can't, for the life of me, figure out how to setup…
Drag-On
  • 362
  • 2
  • 9
7
votes
1 answer

How to get the source text from line number using clang?

I am using clang matcher to obtain the result nodes. From the result nodes, I am able to get the line number, let us say 17. Now, I would like to get the entire source code in that line. Please help. Let me explain in detail. I have a clang matcher…
The Voyager
  • 617
  • 8
  • 21
7
votes
1 answer

Clang user documentation

I was unsure whether to ask here or in superuser, but this site seemed more appropriate I'm looking for documentation/analysis on Clang specifically for these two areas: comparison of warnings provided by Clang vs. GCC I'm specifically looking…
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
7
votes
0 answers

__nat class in clang standard libary

I was looking through clang's C++ standard library, and found this class in the shared_ptr class. class shared_ptr // ... private: struct __nat {int __for_bool_;}; // ... }; I understand that this class is used to detect whether type conversion…
hohohmm
  • 197
  • 1
  • 12
7
votes
1 answer

Template Argument Deduction Broken in Clang 6 for Temporary Objects

Template argument deduction appears to be broken in Clang 6 for temporary objects. g++ 8.1.0 compiles and runs the example correctly. Clang 6.0.0 and 6.0.2 both error at the indicated line with this message: error: expected unqualified-id …
user9816683
  • 105
  • 4
7
votes
1 answer

constexpression in derived class, clang vs rest

Minimal example: #include struct B { constexpr static const size_t MAX = 10; }; struct D : B { constexpr static const size_t MAX = 20; }; void use(const B& v) { static_assert(v.MAX == 10, ""); } template void…
da_m_n
  • 821
  • 7
  • 10
7
votes
1 answer

clang vs gcc: different code for volatile access

Consider this example: volatile unsigned int x; unsigned int y; void f() { x /= 2; } void g() { y /= 2; } When compiled with -Os, clang-6.0 produces on x64 for both f and g the same shrl (%rip) instruction pattern (See…
Nordic Mainframe
  • 28,058
  • 10
  • 66
  • 83
7
votes
1 answer

how to use standard library with C++ modules? (eg: `import std.io`)

The basic example given in How do I use C++ modules in Clang? works for me but doesn't import the standard library (eg via import std.stdio;); after going over http://clang.llvm.org/docs/Modules.html it wasn't clear how to use the standard library…
timotheecour
  • 3,104
  • 3
  • 26
  • 29
7
votes
1 answer

gcc and clang throw "no matching function call" but msvc (cl) compiles and works as expected

I have written a small function template that joins different containers in a new container: #include #include #include #include #include namespace impl { template
Timo
  • 9,269
  • 2
  • 28
  • 58
7
votes
2 answers

How to use (link) debug version of libc++ in macOS?

I want to enable debug version of libc++ in macOS, so I define _LIBCPP_DEBUG=1 in cxx_build_flags [Debug Version of libC++], but unable to link debug function of libc++. I guess there is only release version of libc++ in my system, so how can I get…
Jack chen
  • 71
  • 3
7
votes
1 answer

Is it possible to override virtual functions with external friend lambda functions?

I am writing some game code. I have an abstract game object class, and I want to make many various instances of the class. I want to write them quickly, without writing subclasses for each of them, so I tried to override the virtual functions with…
vabuff
  • 73
  • 5