https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83445
Bug ID: 83445
Summary: conversion function has too high priority in overload
resolution
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: omawarisan.bokudesu at live dot jp
Target Milestone: ---
In the following program, overload resolution in the
direct-initialization of `target` from `source` (in the main function)
should select `Target(Source const&)` directly,
but gcc 7.2.0 and trunk with -std=c++17 uses `Source::operator Target()` .
I believe the former should be selected because a standard conversion sequence
is always better than a user-defined conversion sequence.
command: g++ test.cpp -std=c++17 -pedantic test.cpp
expected behavior: prints "OK"
actual behavior: prints "Bad"
#include <cstdio>
struct Source;
struct Target
{
Target() = default;
Target(Source const&){
std::printf("OK\n");
value = 0;
}
int value = -1;
};
struct Source
{
operator Target(){
std::printf("Bad\n");
Target target;
target.value = 1;
return target;
}
};
int main()
{
Source source;
Target target{source};
std::printf("v = %d\n", target.value);
}
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/data2/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /data2/gcc-trunk/gcc/configure --prefix=/data2/gcc-trunk
--enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 8.0.0 20171215 (experimental) (GCC)