From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF16E3858D38; Thu, 11 Apr 2024 16:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF16E3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712853922; bh=mkUvBXD7nrXbLM+eE2I+9fqxW3pLocR1AqUxWOcbo7I=; h=From:To:Subject:Date:From; b=BbTBtgVKaS7RLNPHS2YiiUGMzjWZwHvabqqYnf0WSuyTS+r/oFAvfoAnDN/ON9eyX 2lSiSHKqfpHIChwJ3b13s85Va27guaWZooqtyyj+aJx3SE+QnFLWDBYAQyHUHFJ4MZ Wu0kxL9fugwjbDQFxt56t9z9yF4+ttoKaGIhkUPw= From: "vin.piquet at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114695] New: Template argument deduction and defaulted template template parameters Date: Thu, 11 Apr 2024 16:45:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vin.piquet at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114695 Bug ID: 114695 Summary: Template argument deduction and defaulted template template parameters Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vin.piquet at gmail dot com Target Milestone: --- =3D=3D=3D=3D test.cpp =3D=3D=3D=3D template struct Bar { void accept(X value) { } }; template struct Foo; template struct Foo...> : Bar... { template typename B =3D Ba= r> constexpr static B* slice_by_type(B* self) { return self; } template void accept(Us... values) { (slice_by_type(this)->accept(values), ...); } }; int main() { Foo, Bar<1, int>> foo; foo.accept(3.14f, 10); } =3D=3D=3D=3D test.cpp =3D=3D=3D=3D GCC rejects this code with the following error =3D=3D=3D=3D console output for GCC 13.2 =3D=3D=3D=3D test.cpp: In instantiation of 'void Foo...>::accept(Us ...) [wi= th Us =3D {float, int}; int ...Is =3D {0, 1}; Ts =3D {float, int}]': test.cpp:22:15: required from here test.cpp:16:27: error: no matching function for call to 'Foo, Bar<1, int> >::slice_by_type(Foo, Bar<1, int> >*)' 16 | (slice_by_type(this)->accept(values), ...); | ~~~~~~~~~~~~~~~~~^~~~~~ test.cpp:10:31: note: candidate: 'template, class> class B> static constexpr B* Foo...>::slice_by_type(B*) [with int I =3D T; B =3D I; int ...Is =3D = {0, 1}; Ts =3D {float, int}]' 10 | constexpr static B* slice_by_type(B* self) { | ^~~~~~~~~~~~~ test.cpp:10:31: note: template argument deduction/substitution failed: test.cpp:16:27: note: 'B' is an ambiguous base class of 'Foo, Bar<1, int> >' 16 | (slice_by_type(this)->accept(values), ...); | ~~~~~~~~~~~~~~~~~^~~~~~ This appears to be a consequence of GCC matching T to I somehow and getting confused. I can't really tell what's going on here, except that the fact GCC seems to not deduce I =3D 0 supposedly because B is not deduced to Ba= r<0, float>. Interestingly, GCC 6.3 also rejects this code, with a somewhat more clear error: =3D=3D=3D=3D Console output for GCC 6.3 =3D=3D=3D=3D test.cpp: In instantiation of 'void Foo...>::accept(Us ...) [wi= th Us =3D {float, int}; int ...Is =3D {0, 1}; Ts =3D {float, int}]': :22:25: required from here :16:27: error: no matching function for call to 'Foo, Bar<1, int> >::slice_by_type(Foo, Bar<1, int> >*)' (slice_by_type(this)->accept(values), ...); ~~~~~~~~~~~~~~~~~^~~~~~ test.cpp:10:31: note: candidate: template, class> class B> static constexpr B* Foo...>::slice_by_type(B*) [with T =3D T; int I =3D I; B =3D B; int .= ..Is =3D {0, 1}; Ts =3D {float, int}] constexpr static B* slice_by_type(B* self) { ^~~~~~~~~~~~~ test.cpp:10:31: note: template argument deduction/substitution failed: test.cpp:16:27: error: type/value mismatch at argument 1 in template parame= ter list for 'template, class> class B' (slice_by_type(this)->accept(values), ...); ~~~~~~~~~~~~~~~~~^~~~~~ test.cpp:16:27: note: expected a constant of type 'int', got 'Bar<0, floa= t>' =3D=3D=3D=3D Console output for GCC 6.3 =3D=3D=3D=3D MSVC accepts this code in C++20 but rejects it in C++17 with a similar erro= r; Clang accepts this code on both versions since Clang 5.0.0 Relevant godbolt link: https:~~godbolt.org~z~48zs7KnTo (replace tildes) =3D=3D=3D=3D Compiler version =3D=3D=3D=3D Using built-in specs. COLLECT_GCC=3Dg++ COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/aarch64-linux-gnu/13/lto-wrapper Target: aarch64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 13.2.0-4ub= untu3' --with-bugurl=3Dfile:///usr/share/doc/gcc-13/README.Bugs --enable-languages=3Dc,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=3D/usr --with-gcc-major-version-only --program-suffix=3D-13 --program-prefix=3Daarch64-linux-gnu- --enable-shared --enable-linker-build= -id --libexecdir=3D/usr/libexec --without-included-gettext --enable-threads=3Dp= osix --libdir=3D/usr/lib --enable-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=3Drelea= se --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=3Drelease --build=3Daarch64-linux-gnu --host=3Daarch64-linux-gnu --target=3Daarch64-l= inux-gnu --with-build-config=3Dbootstrap-lto-lean --enable-link-serialization=3D2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.0 (Ubuntu 13.2.0-4ubuntu3) =3D=3D=3D=3D Compiler version =3D=3D=3D Thank you :)=