compiler-bug

Clang and the binary fold expressions — The curse of the empty parameter pack

你。 提交于 2019-12-04 02:16:21
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 <class... Args> void foo(Args... args) { std::cout << ... << args; } Triggers the following compilation error : main.cpp:7:17: error: expected ';' after expression std::cout << ... << args; ^ ; main.cpp:7:15: error: expected expression std::cout << ... << args; ^ So I tried putting parentheses around the expression : (std::cout << ... << args); It works, but triggers a warning : main.cpp:7:6: warning:

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

こ雲淡風輕ζ 提交于 2019-12-04 01:54:07
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 first impression it looks like a GCC bug. I feel it should compile as we can initialize a std::array

GCC bug? Chaining methods, broken sequence point

。_饼干妹妹 提交于 2019-12-03 23:25:19
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 <iostream> using namespace std; struct Test { Test& set(int& i){ i = 10; return *this; } Test& print(const int& i){ cout << i << endl; return *this; } }; int main(void){ int i = 0; Test t; t.set(i).print(i + 5); return 0; } I had expected that the print() method here would output 15, but instead it outputs 5. EDIT: 10 days later I just realised that with clang it outputs 15! Is this a bug

Can sizeof nested twice ever be a dependent expression?

笑着哭i 提交于 2019-12-03 23:17:33
I noticed that gcc 5.0 rejects the following code, while clang 3.6 accepts it. template<int n> struct I { typedef int Type; }; template<typename T> struct A { typedef I<sizeof(sizeof(T))>::Type Type; }; The two compilers seem to differ on whether sizeof(sizeof(T)) is a type-dependent or value-dependent expression. If the expression were dependent, then it follows that I<sizeof(sizeof(T))> is a dependent type, meaning that typename should be required. This is covered by the following wording in the C++11 standard: [temp.dep.type]/8 A type is dependent if it is a simple-template-id in which

brace-or-equal-Initializer in unions

我怕爱的太早我们不能终老 提交于 2019-12-03 22:24:58
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_, y_; }; union U { int z; double w; Point p = Point(1,2); }; #include <iostream> int main () { U u; std::cout << u.p.x_ << ":" << u.p.y_ << std::endl; } prints 4196960:0 instead of the expected 1:2 . I consider this a compiler bug. Is that so? C++11 [class.ctor]/5 states: A default constructor for a class X is a constructor of class X that can be called without an

“this” captured by lambda is incorrect. GCC compiler bug?

此生再无相见时 提交于 2019-12-03 19:48:14
问题 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 should get its own this pointer, which points to the App object) It only occurs if a std::cout print statement is present , and called before the lambda is created. The print statement can be seemingly completely unrelated (e.g. print "Hello!").

Possible C# 4.0 compiler error, can others verify?

佐手、 提交于 2019-12-03 17:23:16
问题 Since I don't know exactly what part of it alone that triggers the error, I'm not entirely sure how to better label it. This question is a by-product of the SO question c# code seems to get optimized in an invalid way such that an object value becomes null, which I attempted to help Gary with yesterday evening. He was the one that found out that there was a problem, I've just reduced the problem to a simpler project, and want verification before I go further with it, hence this question here.

Conditional operator's return type and two-phase lookup

这一生的挚爱 提交于 2019-12-03 14:24:59
问题 Consider the following snippet: struct Base { }; struct Derived : Base { }; void f(Base &) { std::cout << "f(Base&)\n"; } template <class T = int> void g() { Derived d; f(T{} ? d : d); // 1 } void f(Derived &) { std::cout << "f(Derived&)\n"; } int main() { g(); } In this case, I reckon that the function call to f at // 1 should be looked up in phase one, since its argument's type is unambigously Derived& , and thus be resolved to f(Base&) which is the only one in scope. Clang 3.8.0 agrees

GCC/Clang x86_64 C++ ABI mismatch when returning a tuple?

时光毁灭记忆、已成空白 提交于 2019-12-03 09:22:34
问题 When trying to optimize return values on x86_64, I noticed a strange thing. Namely, given the code: #include <cstdint> #include <tuple> #include <utility> using namespace std; constexpr uint64_t a = 1u; constexpr uint64_t b = 2u; pair<uint64_t, uint64_t> f() { return {a, b}; } tuple<uint64_t, uint64_t> g() { return tuple<uint64_t, uint64_t>{a, b}; } Clang 3.8 outputs this assembly code for f : movl $1, %eax movl $2, %edx retq and this for g : movl $2, %eax movl $1, %edx retq which look

Possible C# 4.0 compiler error, can others verify?

只愿长相守 提交于 2019-12-03 06:13:04
Since I don't know exactly what part of it alone that triggers the error, I'm not entirely sure how to better label it. This question is a by-product of the SO question c# code seems to get optimized in an invalid way such that an object value becomes null , which I attempted to help Gary with yesterday evening. He was the one that found out that there was a problem, I've just reduced the problem to a simpler project, and want verification before I go further with it, hence this question here. I'll post a note on Microsoft Connect if others can verify that they too get this problem, and of