https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80451
Bug ID: 80451 Summary: return implicit type conversion to std::optional does not compile Product: gcc Version: 6.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: krisk0.2017.02.27 at protonmail dot com Target Milestone: --- Host: x86_64-pc-linux-gnu Target: x86_64-pc-linux-gnu Build: x86_64-pc-linux-gnu Created attachment 41213 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41213&action=edit preprocessed source * Short story: under certain conditions, `return v;` statement does not compile. * the exact version of GCC; gcc-6.3.0 (Gentoo 6.3.0 p1.0) 6.3.0 * the system type; Gentoo on x86_64 * the options given when GCC was configured/built; COLLECT_GCC=gcc-6.3.0 COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/portage/sys-devel/gcc-6.3.0/work/gcc-6.3.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/6.3.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.3.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.3.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/6.3.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/6.3.0/python --enable-languages=c,c++ --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --disable-nls --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 6.3.0 p1.0' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --disable-libmpx --enable-vtable-verify --enable-libvtv --disable-libquadmath --enable-lto --without-isl --enable-libsanitizer --disable-default-pie --disable-default-ssp Thread model: posix gcc version 6.3.0 (Gentoo 6.3.0 p1.0) * the complete command line that triggers the bug; gcc-6.3.0 -xc++ -O2 -std=gnu++14 return-bug.c * the compiler output (error messages, warnings, etc.); return-bug.cc: In function 'std::experimental::fundamentals_v1::optional<Bread_and_butter> meal(std::__cxx11::string)': return-bug.cc:39:12: error: could not convert 'b' from 'Bread_and_butter' to 'std::experimental::fundamentals_v1::optional<Bread_and_butter>' return b; ^ * the preprocessed file (*.i*) that triggers the bug see attachment * Why the code should compile 1. According to C++ standard ยง6.6.3 `The value of the expression is implicitly converted to the return type of the function in which it appears.` 2. According to http://en.cppreference.com/w/cpp/experimental/optional/optional, non-explicit constructor from T& to std::experimental::optional<T> should exist. 3. The code compiles under gcc 5.4