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
19
votes
4 answers
Why does this generics scenario cause a TypeLoadException?
This got a bit long-winded, so here's the quick version:
Why does this cause a runtime TypeLoadException? (And should the compiler prevent me from doing it?)
interface I
{
void Foo();
}
class C
{
public void Foo() where T2 : T1 {…

Igby Largeman
- 16,495
- 3
- 60
- 86
18
votes
1 answer
Can you `= delete` a templated function on a second declaration?
Consider the following code:
template int foo();
template int foo() = delete;
is this valid C++11?
GCC (9.1) says: Yes!
clang (8.0) says: No!
nvcc (9.2) says: No!
MSVC (19.20) says: Yes! (in C++14 mode, it doesn't support…

einpoklum
- 118,144
- 57
- 340
- 684
18
votes
2 answers
"this" captured by lambda is incorrect. GCC compiler bug?
For the last few days, I have been debugging a weird issue involving lambdas in C++. I have reduced the problem down to the following symptoms:
The this pointer gets corrupted inside a lambda (note: this is always captured by copy, so the lambda…

gbmhunter
- 1,747
- 3
- 23
- 24
18
votes
2 answers
Compiler Bug in Visual C++ 10.0 SP1 - cl.exe version 16.0.40219.1 Access violation [confirmed]
I have ran into a problem compiling some template code with Visual Stuido 2010 SP1, cl.exe version 16.0.40219.1
The following code will cause the compiler to access violate:
template
class A
{
A(){}
};
template
class B :…

namezero
- 2,203
- 3
- 24
- 37
17
votes
1 answer
Why is move constructor not picked when returning a local object of type derived from the function's return type?
The following code is rejected by both Clang and GCC (trunk versions):
#include
struct Base
{
Base() = default;
Base(Base const&) = delete;
Base(Base&&) = default;
};
struct Derived : Base
{
Derived() = default;
…

Andy Prowl
- 124,023
- 23
- 387
- 451
16
votes
1 answer
GCC - two identical functions but the code generated differs. Why?
The code:
#define OPPOSITE(c) (*((typeof(x) *)&(x)))
int foo(volatile int x)
{
OPPOSITE(x) = OPPOSITE(x) + OPPOSITE(x);
return x;
}
int bar(volatile int x)
{
OPPOSITE(x) = OPPOSITE(x) + OPPOSITE(x);
return x;
}
The result…

0___________
- 60,014
- 4
- 34
- 74
16
votes
1 answer
Can sizeof nested twice ever be a dependent expression?
I noticed that gcc 5.0 rejects the following code, while clang 3.6 accepts it.
template
struct I
{
typedef int Type;
};
template
struct A
{
typedef I::Type Type;
};
The two compilers seem to differ on…

willj
- 2,991
- 12
- 24
15
votes
1 answer
MSVC: Invalid memcpy optimization?
Consider the following code:
void MemMove8(void* dst, void* src)
{
char tmp[8];
memcpy(tmp, src, 8);
memcpy(dst, tmp, 8);
}
MSVC (16.7.1) x86 with /O2 generates the following assembly for this function:
; _dst$ = ecx
; _src$ = edx
…

Alex
- 709
- 3
- 10
15
votes
3 answers
C++ Preprocessor Standard Behaviour
I'm studying the C++ standard on the exact behaviour the preprocessor (I need to implement some sort of C++ preprocessor). From what I understand, the example I made up (to aid my understanding) below should be valid:
#define dds(x) f(x,
#define…

JavaMan
- 4,954
- 4
- 41
- 69
15
votes
3 answers
GCC bug? Chaining methods, broken sequence point
I've been debugging a program for some time, and eventually found the error was due to a reference not being updated as I thought it would be.
Here's a example that shows the problem I encountered:
#include
using namespace std;
struct…

Xeno
- 451
- 2
- 13
14
votes
3 answers
Unexpected x64 assembly for __atomic_fetch_or with gcc 7.3
I am attempting to use a 64-bits integral as a bitmap, and acquire/release ownership of individual bits, atomically.
To this end, I have written the following lock-less code:
#include
#include
static constexpr std::uint64_t…

Matthieu M.
- 287,565
- 48
- 449
- 722
14
votes
2 answers
GCC/Clang x86_64 C++ ABI mismatch when returning a tuple?
When trying to optimize return values on x86_64, I noticed a strange thing. Namely, given the code:
#include
#include
#include
using namespace std;
constexpr uint64_t a = 1u;
constexpr uint64_t b = 2u;
pair

jotik
- 17,044
- 13
- 58
- 123
14
votes
3 answers
Clang and the binary fold expressions — The curse of the empty parameter pack
Specifically Clang 3.6.0, the one currently hosted by Coliru.
All these snippets are called from :
int main() {
foo();
std::cout << "\n----\n";
foo(1, 2, 3);
}
The following code :
template
void foo(Args... args) {
…

Quentin
- 62,093
- 7
- 131
- 191
14
votes
3 answers
Are explicit conversion operators allowed in braced initializer lists?
The following code compiles with GCC 4.9.2 but not with Clang 3.5.0:
#include
class Foo
{
public:
explicit operator std::string() const;
};
std::string bar{Foo{}}; // Works in g++, fails in clang++
std::string baz(Foo{}); // Works in…

Tavian Barnes
- 12,477
- 4
- 45
- 118
14
votes
2 answers
Why variadic function can't "eat" the list-initialization argument in C++11?
The sample code is:
#include
int main() {
std::unordered_map> map;
map.emplace(1, {1, 1});
return 0;
}
Where the emplace() has signature, like:
template
pair…

abyss.7
- 13,882
- 11
- 56
- 100