https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119685
Bug ID: 119685
Summary: deduction guide sometimes ignored in a function call
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jonathan.poelen at gmail dot com
Target Milestone: ---
The following code fails to compile when the template type to be deduced is
used as the first parameter and constructed with parentheses and a variable.
I have the impression that this is confused with MVP.
```cpp
template<class T>
struct checked_int
{
checked_int(T i) : i(i) {}
operator int () const { return i; }
T i;
};
struct Foo { Foo(int, int) {} };
int main()
{
int n = 1;
Foo foo(checked_int(n), checked_int(n*n)); // error
Foo bar(checked_int(n*n), checked_int(n)); // Ok
}
```
with -std=c++17 or -std=c++20
```
test.cpp: In function ‘int main()’:
test.cpp:16:11: error: missing template argument list after ‘checked_int’;
template placeholder not permitted in parameter
16 | Foo foo(checked_int(n), checked_int(n*n)); // error
| ^~~~~~~~~~~
| <>
test.cpp:16:11: note: or use ‘auto’ for an abbreviated function template
test.cpp:2:8: note: ‘template<class T> struct checked_int’ declared here
2 | struct checked_int
| ^~~~~~~~~~~
```
Works with clang and msvc.
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20250207 (GCC)