https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116710
Bug ID: 116710 Summary: Deduction succeeds despite mismatch of reference kind (lvalue versus rvalue) Product: gcc Version: 15.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com Target Milestone: --- GCC allows template argument deduction to succeed even when deducing an lvalue reference type (i.e., not a forwarding reference) from an rvalue reference type. As demonstrated by the case below, this can cause SFINAE to fail and trigger errors outside the immediate context. Note: The forwarding reference behaviour that allows a forwarding reference to be deduced as an lvalue reference does not apply in the deduction context involved below anyway. MSVC has a similar bug. Online compiler link: https://godbolt.org/z/8o48Pr6rW ### SOURCE (<stdin>): template <typename T> struct A : T {}; template <typename T> void f(void (*)(T &), typename A<T>::type * = 0); void f(...); void g(int &&); void q() { f(g); } ### COMPILER INVOCATION: g++ -fsyntax-only -std=c++11 -xc++ - ### EXPECTED OUTPUT: (clean compile) ### ACTUAL OUTPUT: <stdin>: In instantiation of 'struct A<int>': <stdin>:4:6: required by substitution of 'template<class T> void f(void (*)(T&), typename A<T>::type*) [with T = int]' <stdin>:10:13: required from here <stdin>:1:30: error: base type 'int' fails to be a struct or class type ### COMPILER VERSION INFO (g++ -v): Using built-in specs. COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++ COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls --enable-lto LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32 Thread model: posix Supported LTO compression algorithms: zlib gcc version 15.0.0 20240913 (experimental) (GCC)