https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62659

            Bug ID: 62659
           Summary: [4.9 regression] Regression in template argument
                    substitution in 4.9+
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rbd at debian dot org

This is probably related to PR c++/61488 although slightly more complicated. 
The following test case is accepted by gcc 4.8 (and clang) but fails on 4.9.1
and a recent 5.0 snapshot.  If I get rid of the "template <bool>" in front of
fix() then it compiles on all compilers.  AFAIK there is no C++ language reason
why it should matter whether fix() is a template or not when compiling its
body.

~$ cat b.cpp
struct D {
        typedef int (D::*cont_func)();
        template <cont_func> struct B;
        template <cont_func cont_f> void wait(B<cont_f> ***);

        int done();
        template <bool> void fix() { wait<&D::done>(0); }
};

~$ for CC in gcc-4.8 clang gcc-4.9 /usr/lib/gcc-snapshot/bin/gcc; do echo "===
$CC ("`$CC --version`")" ===; $CC -Wall -Werror -c b.cpp && echo SUCCESS; echo;
done ; gcc-4.9 -v -c b.cpp
=== gcc-4.8 (gcc-4.8 (Ubuntu 4.8.3-9ubuntu1) 4.8.3 Copyright (C) 2013 Free
Software Foundation, Inc. This is free software; see the source for copying
conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.) ===
SUCCESS

=== clang (Ubuntu clang version 3.5.0-+rc3-1ubuntu1 (tags/RELEASE_350/rc3)
(based on LLVM 3.5.0) Target: x86_64-pc-linux-gnu Thread model: posix) ===
SUCCESS

=== gcc-4.9 (gcc-4.9 (Ubuntu 4.9.1-9ubuntu1) 4.9.1 Copyright (C) 2014 Free
Software Foundation, Inc. This is free software; see the source for copying
conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.) ===
b.cpp: In member function ‘void D::fix()’:
b.cpp:7:54: error: no matching function for call to ‘D::wait(int)’
         template <bool> void fix() { wait<&D::done>(0); }
                                                      ^
b.cpp:7:54: note: candidate is:
b.cpp:4:42: note: template<int (D::* cont_f)()> void D::wait(D::B<cont_f>***)
         template <cont_func cont_f> void wait(B<cont_f> ***);
                                          ^
b.cpp:4:42: note:   template argument deduction/substitution failed:
b.cpp: In substitution of ‘template<int (D::* cont_f)()> void
D::wait(D::B<cont_f>***) [with int (D::* cont_f)() = (&((D*)this)->*D::done)]’:
b.cpp:7:54:   required from here
b.cpp:4:42: error: ‘&((D*)this)->*D::done’ is not a valid template argument for
type ‘int (D::*)()’
b.cpp:4:42: error: it must be a pointer-to-member of the form ‘&X::Y’
b.cpp:4:42: error: could not convert template argument ‘&((D*)this)->*D::done’
to ‘int (D::*)()’

=== /usr/lib/gcc-snapshot/bin/gcc (gcc (Ubuntu 20140821-0ubuntu1) 5.0.0
20140821 (experimental) [trunk revision 214260] Copyright (C) 2014 Free
Software Foundation, Inc. This is free software; see the source for copying
conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.) ===
b.cpp: In member function 'void D::fix()':
b.cpp:7:54: error: no matching function for call to 'D::wait(int)'
         template <bool> void fix() { wait<&D::done>(0); }
                                                      ^
b.cpp:4:42: note: candidate: template<int (D::* cont_f)()> void
D::wait(D::B<cont_f>***)
         template <cont_func cont_f> void wait(B<cont_f> ***);
                                          ^
b.cpp:4:42: note:   template argument deduction/substitution failed:
b.cpp: In substitution of 'template<int (D::* cont_f)()> void
D::wait(D::B<cont_f>***) [with int (D::* cont_f)() = (&((D*)this)->*D::done)]':
b.cpp:7:54:   required from here
b.cpp:4:42: error: '&((D*)this)->*D::done' is not a valid template argument for
type 'int (D::*)()'
b.cpp:4:42: error: it must be a pointer-to-member of the form '&X::Y'
b.cpp:4:42: error: could not convert template argument '&((D*)this)->*D::done'
to 'int (D::*)()'

Using built-in specs.
COLLECT_GCC=gcc-4.9
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.1-9ubuntu1'
--with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.9 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify
--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.9-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-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,mx32 --enable-multilib
--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.9.1 (Ubuntu 4.9.1-9ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9.1/cc1plus -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE b.cpp -quiet -dumpbase b.cpp -mtune=generic
-march=x86-64 -auxbase b -version -fstack-protector-strong -Wformat
-Wformat-security -o /tmp/cccB3SIf.s
GNU C++ (Ubuntu 4.9.1-9ubuntu1) version 4.9.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2-p3,
MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.9"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.9
 /usr/include/x86_64-linux-gnu/c++/4.9
 /usr/include/c++/4.9/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.9.1-9ubuntu1) version 4.9.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2-p3,
MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c7c99c3366f98ee5a8a37cc0f237cd94
b.cpp: In member function ‘void D::fix()’:
b.cpp:7:54: error: no matching function for call to ‘D::wait(int)’
         template <bool> void fix() { wait<&D::done>(0); }
                                                      ^
b.cpp:7:54: note: candidate is:
b.cpp:4:42: note: template<int (D::* cont_f)()> void D::wait(D::B<cont_f>***)
         template <cont_func cont_f> void wait(B<cont_f> ***);
                                          ^
b.cpp:4:42: note:   template argument deduction/substitution failed:
b.cpp: In substitution of ‘template<int (D::* cont_f)()> void
D::wait(D::B<cont_f>***) [with int (D::* cont_f)() = (&((D*)this)->*D::done)]’:
b.cpp:7:54:   required from here
b.cpp:4:42: error: ‘&((D*)this)->*D::done’ is not a valid template argument for
type ‘int (D::*)()’
b.cpp:4:42: error: it must be a pointer-to-member of the form ‘&X::Y’
b.cpp:4:42: error: could not convert template argument ‘&((D*)this)->*D::done’
to ‘int (D::*)()’

Reply via email to