2,119 questions
0
votes
0
answers
60
views
check_ipo_supported returns false on windows when using clang++ provided by MSYS2
On windows, using check_ipo_supported CMake function gives the following results:
compiler
generator
check_ipo_supported
msvc
NMake Makefiles
TRUE
g++ (from MSYS2)
MinGW Makefiles
TRUE
clang++ (from ...
1
vote
1
answer
50
views
How can I correlate a clang::CXXMethodDecl with documentation comments that are in the header?
I am learning to work with the clang AST while developing a refactoring tool.
I'm using a clang::ast_matchers::dynamic::DynTypedMatcher created using the clang::ast_matchers::dynamic::Parser::...
2
votes
3
answers
239
views
How to detect C++20 mode of compilation?
When compiling my program using a recent version of OpenVDB library by Clang in C++20 mode, I get the error:
error: use of the 'assume' attribute is a C++23 extension
I see that it is due to the ...
1
vote
1
answer
100
views
How to rebuild Clang 16.0.0 on Ubuntu 22.04 so it links with `libtinfo6` instead of `libtinfo5`?
I’m working on a legacy C++ codebase that ships with its own Clang 16 inside a thirdparty/llvm-build-16 folder. On our new Ubuntu 22.04 build system, this bundled compiler fails to run because it ...
0
votes
0
answers
32
views
How to combine PyVarObject_HEAD_INIT and designated initializers?
In my own "native" Python module I declare a new type this way:
PyTypeObject calculatorType = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "My.Calculator",
.tp_basicsize ...
5
votes
2
answers
161
views
Is this assignment to brace-enclosed string constant really illegal in C++?
I am porting a large codebase from Linux/g++ to MacOS/Clang. I hit this compiler error in multiple places in Clang (where g++ builds successfully and does the right thing at run time):
error: ...
1
vote
0
answers
39
views
Can HWASAN support runtime suppressions?
The design document for Hardware-assisted AddressSanitizer does not document whether or not runtime suppressions are possible using the HWASAN_OPTIONS environment variable.
Assuming a program compiled ...
2
votes
2
answers
112
views
Can clang -ffast-math optimize away comparison between quiet_NaN and float?
I noticed that the following program optimizes to no instructions at all on recent versions of clang, with -ffast-math and -O1 and higher:
#include <cassert>
#include <limits>
int main() {...
-3
votes
1
answer
127
views
Why does this program trap, kill or result in a segmentation fault? [duplicate]
Platform: aarch64, android 14, clang 20.1.6 (latest version), llvm 20.1.6, kernel 5.4.254-qgki-ga443
Code:
int start_game(void) {
}
int main(int argc, char **argv) {
start_game();
}
Problem: My ...
0
votes
0
answers
20
views
Getting all exception specifications in Clang
I am working on a program that outputs a C++ AST to a form that can be injested by the Rocq theorem prover. For many things, this works well, but Clang seems to compute some information lazily and ...
10
votes
1
answer
227
views
Why does this C++ operator overloading code work in Clang but not GCC/MSVC with C++20?
I recently encountered an interesting C++ code example that compiles with Clang (-std=c++20) but fails with GCC and MSVC. The code involves operator overloading and friend function declarations.
Code ...
5
votes
1
answer
196
views
Why does std::is_sorted() change between calls with clang
I have some code which is showing odd behavior when std::is_sorted() is called twice in a row; the result changes! The fist call returns false and the second call returns true. This happens with the ...
2
votes
0
answers
336
views
How do I avoid both modernize-deprecated-headers and misc-include-cleaner warnings?
I'm trying to remove all clang-tidy warnings in my C++ project. But I get alternating modernize-deprecated-headers and misc-include-cleaner warnings.
For example:
I use open_memstream in a file, so I ...
4
votes
1
answer
184
views
Why doesn't GCC allow a constexpr std::string while Clang does?
I'm using GCC 14 and Clang 21. Why is the next C++23 code refused by GCC but Clang compiles without problems ? Both seems to support this functionality of C++20 and I'm using C++23. I think I've read ...
0
votes
0
answers
30
views
clang++ option to turn off literal operators
I've been doing some tests to try to use LLVM to build a big 20 year old project developed with GCC.
Among the vast number of issues one of the problems is with old Qt headers. We're building with -...
3
votes
0
answers
60
views
constexpr if with function parameter error with clang, gcc is ok
Here is the test code:
#include <type_traits>
enum class ShaderType:unsigned{
Vertex = 0,
Fragment = 1,
};
template<ShaderType type> struct ShaderTypeHolder{
static constexpr ...
1
vote
0
answers
16
views
How do I update my c++ version on a Mac M2 [duplicate]
I have been dealing with a lot of errors in my C++ code and then just realized I am running c++ 98. I am writing this for some help with updating it to c++20 or 17. From everything I have read, I have ...
0
votes
0
answers
135
views
Attempting build LLVM for iOS-simulator platform instead of macOS
I’m currently testing an interesting ARM64-to-x86_64 emulator implemented within the Xcode iOS Simulator. The goal is to enable Intel Macs to run ARM64 iOS binaries.
Part of the emulator’s code relies ...
0
votes
0
answers
57
views
Understanding `omp_orig` in a custom OpenMP reduction
I've encountered a bug when using Clang[1] with libomp[2] whereby using omp_priv = omp_orig in the initializer of a custom OpenMP reduction silently gives erroneous output. For example:
/* file.cpp */
...
1
vote
1
answer
307
views
Link the OpenMP library statically in C/C++
I have a simple C++ program that does nothing:
int main() { return 0; }
I am trying to build this program completely statically using the following command:
g++ -o c c.cc -static
Everything works ...
4
votes
1
answer
124
views
Is it compile bug? Accessing inactive member of union in constexpr function causes compile error in compile time evaluation
While I was playing with constexpr function, I faced the following issue.
Accessing inactive member of union is undefined behaviour I know. But there is one exception for this rule.
According to C++23 ...
1
vote
0
answers
119
views
Refactor return type using clang transformer
Assume the following function:
const std::vector<std::unique_ptr<T>>& Foo::bar();
I'd like to refactor it to:
const std::vector<T>& Foo::bar();
And then, I'd like to ...
2
votes
2
answers
197
views
AppleClang 15: no member named 'fetch_add' in 'std::atomic<float>'
I have a C++20 program that can be successfully built in Ubuntu 20 with GCC 10 or in Visual Studio 2019. And now I need to compile it for macOS 13.7.2 x64 (currently available on GitHub-hosted runner),...
0
votes
1
answer
39
views
How does LLVM distinguish between clang and clang++ commands?
I'm exploring the LLVM/Clang source code and interested in understanding how LLVM distinguishes between clang and clang++ commands, knowing that clang++ is often considered an alias of clang. Which ...
1
vote
2
answers
154
views
std::vector: why out_of_range error doesn't happen?
Mac M1.
I learn C++ by Bjarne Stroustrup's book. He show the similar example in his "Programming. Principles and Practice Using C++" book (chapter 5.6.2). Also he writes this exception (...