http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57570
Bug ID: 57570 Summary: Deduction succeeds despite type mismatch of non-type template parameter and deduced argument Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: hstong at ca dot ibm.com GCC does not consistently fail deduction for type mismatch of a non-type template parameter and the corresponding deduced argument. See N3690 subclause 14.8.2.5 [temp.deduct.type] paragraph 17. ### STANDALONE SOURCE: template <short, char> struct A; int foo(void *); template <short x> int foo(A<x, x> *ap) // neither clang++ nor g++ bother to look at the second instance of x // for deduction { return noGood(ap); } int bar(void *); template <char y> int bar(A<y, y> *ap) // okay; clang++ and g++ both realize that deducing from the first instance // of y is no good { return noGood(ap); } int zip(void *, void *); template <short x, char y> int zip(A<x, y> *ap, A<y, x> *) // clang++ does not bother to look at the second function argument // for deduction, g++ does { return noGood(ap); } A<0, 0> *ap = 0; int a = foo(ap); // clang++ and g++ both fail to fail the argument deduction int b = bar(ap); // clang++ and g++ both successfully fail the deduction int c = zip(ap, ap); // // clang++ fails to fail and g++ successfully fails the argument deduction // For all three: // - MSVC 17.00.51025 fails to fail the argument deduction // - ICC 13.0.1 20121010 and IBM XL C/C++ for AIX 12.1.0.3 work fine ### COMPILER INVOCATION: g++ -std=c++11 -c main.cpp ### EXPECTED OUTPUT: Successful compile. ### ACTUAL OUTPUT: main.cpp: In instantiation of 'int foo(A<x, x>*) [with short int x = 0]': main.cpp:23:15: required from here main.cpp:7:12: error: 'noGood' was not declared in this scope ### g++ -v OUTPUT: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.1-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.8.1 (Ubuntu 4.8.1-2ubuntu1~12.04)