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
1 answer

Is this partial class specialization buggy or is it a bug in clang or gcc?

template struct Foo { template constexpr auto a_method(); }; template template constexpr auto Foo::a_method() { return 42; } template <> template constexpr auto…
vladon
  • 8,158
  • 2
  • 47
  • 91
6
votes
1 answer

clang-tidy: `Loop variable is copied but only used as const reference; consider making it a const reference` - does it really matter?

I'm working on code that clang-tidy is flagging all over the place with Loop variable is copied but only used as const reference; consider making it a const reference Current code: for (auto foo : collection) { ... } What clang-tidy suggests I…
Edward Falk
  • 9,991
  • 11
  • 77
  • 112
6
votes
1 answer

Missed optimization with string_view::find_first_of

Update: relevant GCC bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103798 I tested the following code: #include size_t findFirstE_slow(std::string_view sv) { return sv.find_first_of("eE"); } size_t…
zwliew
  • 438
  • 6
  • 6
6
votes
0 answers

Definition of 'xxx' must be imported from module 'yyy' before it is required

For example, We have a pod 'Dependency3' declared Class A @interface A : NSObject - (void)test; @end pod 'Dependency1' declared Class B and a category of Class A @interface B : NSObject @property (nonatomic, copy) NSString…
cotton
  • 111
  • 4
6
votes
1 answer

get_time parsing error for two digits year

std::get_time is behaving in the same way when the format includes '%y' or '%Y', in both cases it tries to read a four digit year. Am I doing something wrong or is it a bug ? Example code: #include #include void testDate(const…
Pablo Yaggi
  • 1,061
  • 5
  • 14
6
votes
1 answer

Is clang wrongfully reporting ambiguity when mixing member and non-member binary operators?

Consider the following code, which mixes a member and a non-member operator| template struct S { template void operator|(U) {} }; template void operator|(S,int) {} int main() { S() |…
Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
6
votes
2 answers

C++ function with noexcept in this case is actually slower?

I'm trying to experiment with code by myself here on different compilers. I've been trying to lookup the advantages of disabling exceptions on certain functions (via the binary footprint) and to compare that to functions that don't disable…
Noam Rodrik
  • 552
  • 2
  • 16
6
votes
1 answer

Inform c or c++ compiler loop length is mutliple of 8

I want to write the following function in c++ (compiling using gcc 11.1 with -O3 -mavx -std=c++17) void f( float * __restrict__ a, float * __restrict__ b, float * __restrict__ c, int64_t n) { for (int64_t i = 0; i != n; ++i) { a[i] =…
6
votes
1 answer

clang on Windows / msvc: why under FE_UPWARD printf("%.1f\n", 0.0) prints 0.1 instead of 0.0?

Sample code (t928.c): #include #include #if _MSC_VER && ! __clang__ #pragma fenv_access (on) #else #pragma STDC FENV_ACCESS ON #endif int main(void) { int i = fesetround( FE_UPWARD ); if ( ! i ) { …
pmor
  • 5,392
  • 4
  • 17
  • 36
6
votes
1 answer

Why does Clang 12 refuse to initialize aggregates in the C++20 way?

As far as I understand, the following program should work in C++20 mode: #include struct B{ int a0, a1; }; int main() { std::vector bs; bs.emplace_back( 0, 0 ); } And it really does in Visual Studio 2019 and gcc 11. But not…
Fedor
  • 17,146
  • 13
  • 40
  • 131
6
votes
1 answer

error when install mysqlclient using pip to MacOS Bigsur

I've tried common solutions written for mysqlclient error 1st try: brew install mysql-connector-c 2nd try: LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient 3rd try: brew install zstd And mysql server is well-running. But the error is…
victory
  • 151
  • 2
  • 9
6
votes
1 answer

Compiler variance for ambiguous copy-assignment from empty-braces

I've been trying to understand the rationale for std::nullopt_t to not be allowed to be DefaultConstructible in C++17 (where it was introduced) and beyond, and stepped over some compiler variance confusion in the process. Consider the following…
dfrib
  • 70,367
  • 12
  • 127
  • 192
6
votes
2 answers

How to configure clangd to find missing external header file?

I am a novice user of clang tools and I am learning c/c++. I have some code that is based on a framework that uses its data structure and build system ( OpenFOAM). I compiled the framework's libraries in a folder in home directory. This framework…
Ali
  • 366
  • 4
  • 11
6
votes
1 answer

_mm_max_ss has different behavior between clang and gcc

I'm trying to cross compile a project using clang and gcc but I'm seeing some odd differences when using _mm_max_ss e.g. __m128 a = _mm_set_ss(std::numeric_limits::quiet_NaN()); __m128 b = _mm_set_ss(2.0f); __m128 c = _mm_max_ss(a,b); __m128…
Biggy Smith
  • 910
  • 7
  • 14
6
votes
1 answer

clang-query: Examining name of template parameter of a function argument's type

I have a big project, and a slew of C++ class member functions of the form: Return CClass::MemberFunction( Arg1 arg1, //... std::weak_ptr listener) { //... } I'm trying to write a matcher that finds…
Eric Niebler
  • 5,927
  • 2
  • 29
  • 43
1 2 3
99
100