Questions tagged [compiler-bug]

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.

309 questions
33
votes
4 answers

Visual Studio 2012 different values Release/Debug mode

This code produces different values in MSVS 2012, Windows 7, when switching between Debug and Release mode: #include using namespace std; int A[20000]; int main() { int shift = 0; int Period = 30; //Fill array for(int i…
32
votes
1 answer

Double free in the C++ standard library using only std::function and std::shared_pointer

I recently came across a weird double-free bug in a program when capturing a shared_ptr in a lambda. I was able to reduce it this the following minimal example: #include #include struct foo { std::function
Patrick Ziegler
  • 787
  • 1
  • 7
  • 20
32
votes
2 answers

VBA takes wrong branch at If-statement - severe compiler bug?

The question mark in the title is only there because I'm very reluctant to call anything a compiler bug, but in this case, I'd be surprised if anyone could explain this behavior in any other way. The code to reproduce the problem is very, very…
GWD
  • 3,081
  • 14
  • 30
29
votes
2 answers

Possible compiler bug in Visual C++ 2012 (x86)?

I'm currently experiencing random floating point errors when compiling for x86 targets using VC++ 11 (CTP Update 1). See the short example "test.cpp" below, and compile using: cl /GL /O2 /EHsc test.cpp /link /MACHINE:X86 The output should be 10 ==…
28
votes
3 answers

Maybe a C# compiler bug in Visual Studio 2015

I think this is a compiler bug. The following console application compiles und executes flawlessly when compiled with VS 2015: namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var…
Peter Perot
  • 1,003
  • 1
  • 10
  • 15
26
votes
2 answers

C# compiler bug? Object initializer syntax used for write-only property in Expression makes csc crash

You may consider this a bug report, however I'm curious if I am terribly wrong here, or if there is an explanation from Eric or someone else at Microsoft. Update This is now posted as a bug on Microsoft Connect. Description Consider the following…
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
26
votes
1 answer

Visual Studio 2019 does not handle aggregate initialization of dynamic array of structs correctly

The code below prints garbage (or zeroes) if compiled with VC++ 2017 and "1122" if compiled with GCC or Clang (https://rextester.com/JEV81255). Is it bug of VC++ or I'm missing something here? #include struct Item { int id; int…
26
votes
2 answers

(Known) compiler bug in VC12?

This program, when compiled with VC12 (in Visual Studio 2013 RTM)[1] leads to a crash (in all build configurations), when really it shouldn't: #include void foo(std::string const& oops = {}) { } int main() { foo(); } I know of two…
sehe
  • 374,641
  • 47
  • 450
  • 633
25
votes
2 answers

Is this failing test that adds zero to a null pointer undefined behaviour, a compiler bug, or something else?

I wrote a lightweight string_view wrapper for a C++14 project, and with MSVC 2017 it is triggering a static_assert at compile-time, yet the same code at run-time is passes the regular assert. My question is, is this a compiler bug, manifest…
24
votes
2 answers

Why are generic and non-generic structs treated differently when building expression that lifts operator == to nullable?

This looks like a bug in lifting to null of operands on generic structs. Consider the following dummy struct, that overrides operator==: struct MyStruct { private readonly int _value; public MyStruct(int val) { this._value = val; } …
sinelaw
  • 16,205
  • 3
  • 49
  • 80
22
votes
2 answers

Why does the compiler evaluate remainder MinValue % -1 different than runtime?

I think this looks like a bug in the C# compiler. Consider this code (inside a method): const long dividend = long.MinValue; const long divisor = -1L; Console.WriteLine(dividend % divisor); It compiles with no errors (or warnings). Seems like a…
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
21
votes
8 answers

"redundant cast to java.lang.Object" warning for necessary cast

Consider this Minimal, Reproducible Example : interface Code { static void main(String[] args) { symbol( String.valueOf( true ? 'a' : true ? 'b' : true ? 'c' : …
Tom Hawtin - tackline
  • 145,806
  • 30
  • 211
  • 305
21
votes
1 answer

brace-or-equal-Initializer in unions

Related: How to initialize a non-POD member in Union The standard says At most one non-static data member of a union may have a brace-or-equal-initializer. But struct Point { Point() {} Point(int x, int y): x_(x), y_(y) {} int x_,…
Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
20
votes
0 answers

Using await inside Interlocked.Exchange crashes the C# compiler

Ignore for a moment the absurdity of awaiting an Enumerable.Range call. It's just there to elicit the crash-y behavior. It just as easily could be a method that's doing some network IO to build a collection of value objects. (Indeed, this was where…
rianjs
  • 7,767
  • 5
  • 24
  • 40
19
votes
1 answer

Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode?

Consider this program: #include template constexpr int adds(const int& a, const int& b) { if (Debug) std::cout << __FUNCTION__ << " called on line " << Line << '\n'; return (a +…
1
2
3
20 21