https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88634
Bug ID: 88634 Summary: [c++17] Error message when deducing templated types for a constructor with more than one argument when using `new` Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jacksonmcneillnospam at gmail dot com Target Milestone: --- Created attachment 45307 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45307&action=edit the preprocessed source given by gcc g++ -v output: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.2.0-7ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 8.2.0 (Ubuntu 8.2.0-7ubuntu1) ----- C++ version: c++17 gcc is unable to deduce class template parameters from class constructor arguments if there are more than one class constructor arguments. The error message gcc gives is also rather confusing, saying that no arguments where specified to the constructor. This only happens when creating the class with `new`. /*! * Compile with: g++ -std=c++17 bug_code.cpp */ template<typename T> class bug_class { public: bug_class(int, T ) { } }; template<typename T> class no_bug_class { public: no_bug_class(T ) { } }; template<typename T> class bug_class_swapped { public: bug_class_swapped(T, int) { } }; template<typename T, typename Y> class bug_class_double_template { public: bug_class_double_template(T, Y) { } }; int main() { bug_class(0,2); new bug_class(0,2); //This errors. no_bug_class(0); new no_bug_class(0); bug_class_swapped(0,1); new bug_class_swapped(0,1); //This errors. bug_class_double_template(1,2); new bug_class_double_template(1,2); //This errors. return 0; } ------- This doesn't happen if you remove `new` and allocate bug_class on the stack. This is demonstrated in the code provided. It seems like gcc is unable to automatically deduce class template arguments from the constructor arguments when a non-templated argument exists within the constructor. In clang++-7, this code compiles just fine. ----- bug_code.cpp: In function ‘int main()’: bug_code.cpp:45:19: error: class template argument deduction failed: new bug_class(0,2); //This errors. ^ bug_code.cpp:45:19: error: no matching function for call to ‘bug_class()’ bug_code.cpp:11:3: note: candidate: ‘template<class T> bug_class(int, T)-> bug_class<T>’ bug_class(int, T ) ^~~~~~~~~ bug_code.cpp:11:3: note: template argument deduction/substitution failed: bug_code.cpp:45:19: note: candidate expects 2 arguments, 0 provided new bug_class(0,2); //This errors. ^ bug_code.cpp:52:27: error: class template argument deduction failed: new bug_class_swapped(0,1); //This errors. ^ bug_code.cpp:52:27: error: no matching function for call to ‘bug_class_swapped()’ bug_code.cpp:29:3: note: candidate: ‘template<class T> bug_class_swapped(T, int)-> bug_class_swapped<T>’ bug_class_swapped(T, int) ^~~~~~~~~~~~~~~~~ bug_code.cpp:29:3: note: template argument deduction/substitution failed: bug_code.cpp:52:27: note: candidate expects 2 arguments, 0 provided new bug_class_swapped(0,1); //This errors. ^ bug_code.cpp:56:35: error: class template argument deduction failed: new bug_class_double_template(1,2); //This errors. ^ bug_code.cpp:56:35: error: no matching function for call to ‘bug_class_double_template()’ bug_code.cpp:37:3: note: candidate: ‘template<class T, class Y> bug_class_double_template(T, Y)-> bug_class_double_template<T, Y>’ bug_class_double_template(T, Y) ^~~~~~~~~~~~~~~~~~~~~~~~~ bug_code.cpp:37:3: note: template argument deduction/substitution failed: bug_code.cpp:56:35: note: candidate expects 2 arguments, 0 provided new bug_class_double_template(1,2); //This errors. -----