[Bug c++/77386] New: Explicit constructor is allowed causing ambiguous initialization call when it shouldn't be allowed
hpmv at google dot com
gcc-bugzilla@gcc.gnu.org
Thu Aug 25 22:46:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77386
Bug ID: 77386
Summary: Explicit constructor is allowed causing ambiguous
initialization call when it shouldn't be allowed
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hpmv at google dot com
Target Milestone: ---
Using g++ 4.8.4, compiling the following code
struct X{
X(int, int) {}
};
struct Y {
explicit Y(X) {}
explicit Y(int, int) {}
};
int main() {
Y({1, 2});
}
with the command line
g++ -Wall -Wextra --std=c++11 main.cpp
fails with the errors
main.cpp: In function ‘int main()’:
main.cpp:11:11: error: call of overloaded ‘Y(<brace-enclosed initializer
list>)’ is ambiguous
Y({1, 2});
^
main.cpp:11:11: note: candidates are:
main.cpp:6:11: note: Y::Y(X)
explicit Y(X) {}
^
main.cpp:5:8: note: constexpr Y::Y(const Y&)
struct Y {
^
main.cpp:5:8: note: constexpr Y::Y(Y&&)
This doesn't make sense because the overload Y::Y(const Y&) and Y::Y(Y&&)
should not be considered since it's not possible to interpret {1, 2} as Y(1, 2)
due to that constructor being marked explicit.
The code compiles in clang 3.4.
More information about the Gcc-bugs
mailing list