[Bug c++/86385] New: calling wrong constructors?
zhonghao at pku dot org.cn
gcc-bugzilla@gcc.gnu.org
Tue Jul 3 09:03:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86385
Bug ID: 86385
Summary: calling wrong constructors?
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zhonghao at pku dot org.cn
Target Milestone: ---
The code is as follow:
struct A {
int* a;
A(int a) : a(new int(a)) {}
~A() { delete a; }
A(const A&) = delete;
A(A&& other) { a = other.a; other.a = 0; };
operator bool() { return true; }
int operator*() { return *a; }
};
static A makeA(int x) { return A(x); }
int main() {
A c = makeA(42) ?: makeA(-1);
return *c;
}
g++ error:
error: lvalue required as unary '&' operand
A c = makeA(42) ?: makeA(-1);
It seems that g++ considers 42 and -1 as const A& or A&& other, instead of
integer values. Or else, it does not produce such a message. I tried clang++.
It accepts the code. For me, the results of clang++ are more reasonable.
More information about the Gcc-bugs
mailing list