For questions about (suspected) incorrect behavior of a compiler. Use with the appropriate language tag and, where applicable, with the tag for the compiler in question.
Questions tagged [compiler-bug]
309 questions
2
votes
0 answers
Clang ignores `__attribute__((aligned))` when used with an alias template
For writing SIMD code, I'd like to use templates to generate vector types with certain alignment. However, clang seems to ignore the alignment attribute when used with an alias template instead of a type alias.
Consider this code (godbolt):
#include…

He3lixxx
- 3,263
- 1
- 12
- 31
2
votes
1 answer
Right bit shift in body of lambda used as a template argument doesn't compile on GCC
GCC doesn't compile this code, while other compilers (clang, msvc) do
template
struct S { };
int main() {
S<[]{int x,y; x< s1; // compiles fine
S<[]{int x,y; x>>y;}> s2; // error
}
error:
error: expected ';' before '>>' token
…

michuu
- 315
- 4
- 10
2
votes
1 answer
Variadic template template wrapper: weird compilers errors, possibly bugs
Over years of template metaprogramming practice, I have encountered all sorts of weird compiler bugs and errors. But with this one, I must say that I am somewhat puzzled. I have no idea which compiler is correct: gcc, clang, msvc, and intel all give…

Vincent
- 57,703
- 61
- 205
- 388
2
votes
1 answer
clang standard library bug or c++ undefined behavior?
Does the following C++ program contain any undefined behavior?
int
main()
{
struct entry
{
uint32_t hash;
uint32_t idx;
};
entry arr[31] = {
{ 7978558, 0}, { 9241630, …

Oliver Young
- 578
- 1
- 4
- 12
2
votes
1 answer
C# Compiler bug: allows for conversion from Nullable to decimal
Consider following code:
public class DecimalWrapper
{
public static implicit operator DecimalWrapper(decimal x) => new();
}
[Fact]
public void Test()
{
// Why this even compiles? Since there is no implicit…

videokojot
- 499
- 3
- 12
2
votes
0 answers
readonly field not initialized - no warning
I have the following class with an obviously uninitialized readonly field. This compiles fine with no erros or warnings:
public class Test
{
readonly string s;
public string GetString() => this.s.ToLower();
}
The fun part comes now. When I…

codymanix
- 28,510
- 21
- 92
- 151
2
votes
0 answers
Assigned register collision when inline assembly compiled with clang
Consider the following sample program (targeting Linux/x86-64):
#include
#include
int main(int argc, char *argv[])
{
unsigned arg1 = strtoul(argv[1], NULL, 0);
unsigned arg2 = strtoul(argv[2], NULL, 0);
asm(
"mov…

Netch
- 4,171
- 1
- 19
- 31
2
votes
0 answers
Is this a compiler bug - strange behavior of a function
I was testing this function and found the behavior is strange
method:
uint8_t func(uint32_t x) {
return std::min(32, ::__builtin_clz(x)) + 1;
}
call this method func(0) returns 32 on my mac laptop which is supposed to be 33, however if I…

Shawn Cao
- 117
- 7
2
votes
0 answers
Unexpected gcc warning: function returns address of local variable - is it a compiler bug?
Following is the minimum working example (ok, in fact it's minimum non-working example :-)). When compiled with gcc (from version 5.0 up to 9.3) it fires the following warning. It even seems to fire the warning only in release build (-02 and…

Mi-La
- 685
- 10
- 18
2
votes
0 answers
MSVC compiler bug when adding 0 to a pointer with /arch:AVX2; related to Warning C26451
I’m having a bug after compiling the below piece of code with /O2, /Ob2, /arch:AVX2 flags. I am using Microsoft Visual Studio Community 2019 Version 16.4.6 on a Win64.
Running the below piece of code results in the following output. Note the middle…

addeconinck
- 31
- 2
2
votes
1 answer
Is this a GCC bug like learncpp.com claims?
In C++ learning website (https://www.learncpp.com/cpp-tutorial/6-9a-dynamically-allocating-arrays/) there is a claim that GCC has a bug related to C-style string initialization when new operator is involved:
As of the time of writing, the GCC still…

Dominic
- 43
- 3
2
votes
0 answers
Successfully accessing final instance field of enclosing instance from a static context
Playing with the special case of Inner classes which have an enclosing block instead of a lexically enclosing instance (Java Language Specification §8.1.3), I wrote following example:
public class Test {
private static final Object o = new…

mbo
- 21
- 2
2
votes
2 answers
nvcc warns about a device variable being a host variable - why?
I've been reading in the CUDA Programming Guide about template functions and is something like this working?
#include
/* host struct */
template
struct Test {
T *val;
int size;
};
/* struct device */
template…

Herzog Igzorn
- 23
- 3
2
votes
2 answers
Why does this use of boost::none fail to compile with nvcc?
I'm trying to compile the following code:
#include
void foo(boost::optional x = boost::none);
placed in the file a.cu, with the CUDA compiler, using the following command line:
nvcc a.cu -c --std=c++11…

einpoklum
- 118,144
- 57
- 340
- 684
2
votes
1 answer
Surprising "inferred type does not conform to upper bound" error
When i try to compile this cut-down example with a compiler from JDK 9, 10, or 11:
public class UpperBounder {
public static void main(String[] args) {
print(Stream.of("a", "z", "b").collect(Collectors.toCollection(TreeSet::new)));
…

Tom Anderson
- 46,189
- 17
- 92
- 133