compiler-bug

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

霸气de小男生 提交于 2019-12-18 05:43:12
问题 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; ^

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

一个人想着一个人 提交于 2019-12-18 05:15:33
问题 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 {

Compiler bug, or non standard code? - Variadic template capture in lambda

[亡魂溺海] 提交于 2019-12-10 14:51:53
问题 I have the following C++11 code; template<typename... T> int g(T... t) { return 0; } template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); } int main() { f(2, 5, 7); } I do believe that it's valid C++11, according to; Section 5.1.2.23 of the standard; A capture followed by an ellipsis is a pack expansion (14.5.3). [ Example: template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); } — end example ]

assignment operator on empty inizializer_list

让人想犯罪 __ 提交于 2019-12-10 14:41:19
问题 can you explain how STL containers handle assignment operator with empty initializer list? when i'll do something like this: vector<int> v; v = { }; the function that is called is not : vector& operator= (initializer_list<value_type> il); but: vector& operator= (vector&& x); on the other hand, when i'll do something similar with my own class: struct A { A& operator= (const A&) { return *this; } A& operator= (A&&) { return *this; } A& operator= (initializer_list<int>) { return *this; } }; /* .

Why does this covariance declaration compile? [duplicate]

吃可爱长大的小学妹 提交于 2019-12-08 19:23:04
问题 This question already has answers here : C# variance annotation of a type parameter, constrained to be value type (2 answers) Closed 6 years ago . Consider this interface: interface Test<out T> where T : struct { } It compiles without errors or warnings. As discussed in this question, and mentioned in the Covariance and Contravariance FAQ: Variance is supported only if a type parameter is a reference type. So why does the above interface compile? It would make sense to fail (or at least warn)

g++ (4.7.2) bug or feature, when initializing static arrays at compile-time?

不问归期 提交于 2019-12-07 07:23:55
问题 Okay, so I was trying to do something clever by initializing a bunch of constexpr static int const arrays at compile-time. Even though the runtime-performance is not at all governed by initializing these arrays, it seemed like a fun little exercise. I wrote a test-setup to see if it was possible, and I ended up being able to do this: struct Test { constexpr static int const array[10] = Array<int, 10, 0, Increment>::array; }; constexpr int const Test::array[10]; int main() { cout << Test:

Oracle JDK and Eclipse JDT compilers disagree! Which is compiling this incorrectly? Unusual generics and inferrence

萝らか妹 提交于 2019-12-07 07:13:33
问题 I have a piece of code which is compiling inconsistently between Oracle JDK 7 and Eclipse JDT 7, but since I'm not sure about which compiler is making the mistake(s) I thought I should ask for opinions here before submitting any bug reports. This is the simplest test I could come up with to demonstrate the inconsistency: interface Foo<S extends Foo<S, T>, T> { // should this compile? public <X extends Foo<S, Y>, Y> Y method1(); // what about this? public <X extends Foo<? extends S, Y>, Y> Y

Constexpr if with a non-bool condition

[亡魂溺海] 提交于 2019-12-06 16:29:54
问题 I seem to have found something that Clang and GCC disagree on. Here's the code: int main() { if constexpr (2) {} } This successfully compiles with GCC 7.4.0, but it fails with Clang 7.0.0 with this error message: test.cpp:3:17: error: constexpr if condition evaluates to 2, which cannot be narrowed to type 'bool' [-Wc++11-narrowing] if constexpr (2) {} ^ 1 error generated. cppreference doesn't seem to mention "narrowing", so this seems like a Clang bug, but I'm not entirely certain. If this is

A bug in GCC implementation of bit-fields

柔情痞子 提交于 2019-12-05 20:25:52
问题 Working in C11, the following struct: struct S { unsigned a : 4; _Bool b : 1; }; Gets layed out by GCC as an unsigned (4 bytes) of which 4 bits are used, followed by a _Bool (4 bytes) of which 1 bit is used, for a total size of 8 bytes. Note that C99 and C11 specifically permit _Bool as a bit-field member. The C11 standard (and probably C99 too) also states under §6.7.2.1 'Structure and union specifiers' ¶11 that: An implementation may allocate any addressable storage unit large enough to

Initializing std::array<char,x> member in constructor using string literal. GCC bug?

99封情书 提交于 2019-12-05 17:06:09
问题 The following example initializing a std::array <char, N> member in a constructor using a string literal doesn't compile on GCC 4.8 but compiles using Clang 3.4. #include <iostream> #include <array> struct A { std::array<char, 4> x; A(std::array<char, 4> arr) : x(arr) {} }; int main() { // works with Clang 3.4, error in GCC 4.8. // It should be the equivalent of "A a ({'b','u','g','\0'});" A a ({"bug"}); for (std::size_t i = 0; i < a.x.size(); ++i) std::cout << a.x[i] << '\n'; return 0; } On