compiler-bug

Why does this Haskell code run slower with -O?

梦想的初衷 提交于 2019-11-29 22:44:49
This piece of Haskell code runs much slower with -O , but -O should be non-dangerous . Can anyone tell me what happened? If it matters, it is an attempt to solve this problem , and it uses binary search and persistent segment tree: import Control.Monad import Data.Array data Node = Leaf Int -- value | Branch Int Node Node -- sum, left child, right child type NodeArray = Array Int Node -- create an empty node with range [l, r) create :: Int -> Int -> Node create l r | l + 1 == r = Leaf 0 | otherwise = Branch 0 (create l m) (create m r) where m = (l + r) `div` 2 -- Get the sum in range [0, r).

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

。_饼干妹妹 提交于 2019-11-29 16:52:13
问题 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; } public override bool Equals(object obj) { return false; } public override int GetHashCode() { return base.GetHashCode(); } public static bool operator ==(MyStruct a, MyStruct b) { return false; } public static bool operator !=(MyStruct a, MyStruct b) { return

Lambda Works on Latest Visual Studio, but Doesn't Work Elsewhere

為{幸葍}努か 提交于 2019-11-29 10:05:19
So I've written a nasty lambda to satisfy a "shortest amount of code necessary to achieve this" question : values.resize(distance( begin(values), remove_if(begin(values), end(values), [i = 0U, it = cbegin(intervals), end = cend(intervals)](const auto&) mutable { return it != end && ++i > it->first && (i <= it->second || (++it, true)); }) )); My problem is that on Visual Studio Community 2015 Update 3 version 14.0.25425.01 this outputs the desired: 4.2 9.1 2.3 0.6 6.4 3.6 1.4 7.5 But on all the other compilers I've tried I get: 4.2 2.3 0.6 1.2 0.3 1.4 2.5 7.5 Can anyone tell me what's causing

Possible compiler bug in MSVC12 (VS2013) with designated initializer

自古美人都是妖i 提交于 2019-11-29 09:34:21
Using VS2013 Update 2, I've stumbled on some strange error message : // test.c int main(void) { struct foo { int i; float f; }; struct bar { unsigned u; struct foo foo; double d; }; struct foo some_foo = { .i = 1, .f = 2.0 }; struct bar some_bar = { .u = 3, // error C2440 : 'initializing' : cannot convert from 'foo' to 'int' .foo = some_foo, .d = 4.0 }; // Works fine some_bar.foo = some_foo; return 0; } Both GCC and Clang accept it. Am I missing something or does this piece of code exposes a compiler bug ? EDIT : Duplicate: Initializing struct within another struct using designated initializer

Why is move constructor not picked when returning a local object of type derived from the function's return type?

痞子三分冷 提交于 2019-11-29 09:11:46
The following code is rejected by both Clang and GCC (trunk versions): #include <memory> struct Base { Base() = default; Base(Base const&) = delete; Base(Base&&) = default; }; struct Derived : Base { Derived() = default; Derived(Derived const&) = delete; Derived(Derived&&) = default; }; auto foo() -> Base { Derived d; return d; // ERROR HERE } Causing the following error: prog.cc: In function 'Base foo()': prog.cc:21:12: error: use of deleted function 'Base::Base(const Base&)' return d; ^ According to [class.copy]/32: When the criteria for elision of a copy/move operation are met, but not for

std::shared_ptr in an std::initializer_list appears to be getting destroyed prematurely

♀尐吖头ヾ 提交于 2019-11-29 08:05:47
Edit: This is indeed caused by a bug in Visual Studio - and it has already been fixed. The issue is not reproducible after applying Update 2 to Visual Studio ( release candidate available here ). I apologize; I thought I was up to date with my patches. I can't for the life of me figure out why I get a seg fault when I run the following code in Visual Studio 2013: #include <initializer_list> #include <memory> struct Base { virtual int GetValue() { return 0; } }; struct Derived1 : public Base { int GetValue() override { return 1; } }; struct Derived2 : public Base { int GetValue() override {

Why does this generics scenario cause a TypeLoadException?

我的梦境 提交于 2019-11-29 05:36:39
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<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class D : C<System.Object>, I { } The exception occurs if you try to instantiate D. Longer, more exploratory version: Consider: interface I { void Foo<T>(); } class C<T1> { public void Foo<T2>() where T2 : T1 { } } class some_other_class { } class D : C<some_other_class>, I { } // compiler error CS0425 This is illegal because the type constraints on C

What's special about R and L in the C++ preprocessor?

老子叫甜甜 提交于 2019-11-29 02:06:29
问题 I ran the following code through the Visual Studio 2013 preprocessor. The output surprises me. Contents of hello.cpp: #define A(j) #j A(A?) A(B?) A(C?) A(D?) A(E?) A(F?) A(G?) A(H?) A(I?) A(J?) A(K?) A(L?) A(M?) A(N?) A(O?) A(P?) A(Q?) A(R?) A(S?) A(T?) A(U?) A(V?) A(W?) A(X?) A(Y?) A(Z?) The command: cl /P hello.cpp hello.i contains: #line 1 "hello.cpp" "A?" "B?" "C?" "D?" "E?" "F?" "G?" "H?" "I?" "J?" "K?" "L" "M?" "N?" "O?" "P?" "Q?" "R" "S?" "T?" "U?" "V?" "W?" "X?" "Y?" "Z?" I ran into

(this == null) in C#!

。_饼干妹妹 提交于 2019-11-28 15:18:47
Due to a bug that was fixed in C# 4, the following program prints true . (Try it in LINQPad) void Main() { new Derived(); } class Base { public Base(Func<string> valueMaker) { Console.WriteLine(valueMaker()); } } class Derived : Base { string CheckNull() { return "Am I null? " + (this == null); } public Derived() : base(() => CheckNull()) { } } In VS2008 in Release mode, it throws an InvalidProgramException. (In Debug mode, it works fine) In VS2010 Beta 2, it doesn't compile (I didn't try Beta 1); I learned that the hard way Is there any other way to make this == null in pure C#? Mehrdad

Lambda Works on Latest Visual Studio, but Doesn't Work Elsewhere

假如想象 提交于 2019-11-28 03:26:09
问题 So I've written a nasty lambda to satisfy a "shortest amount of code necessary to achieve this" question: values.resize(distance( begin(values), remove_if(begin(values), end(values), [i = 0U, it = cbegin(intervals), end = cend(intervals)](const auto&) mutable { return it != end && ++i > it->first && (i <= it->second || (++it, true)); }) )); My problem is that on Visual Studio Community 2015 Update 3 version 14.0.25425.01 this outputs the desired: 4.2 9.1 2.3 0.6 6.4 3.6 1.4 7.5 But on all the