Bug 61488 - [4.9 regression] Regression in template argument substitution in 4.9+
Summary: [4.9 regression] Regression in template argument substitution in 4.9+
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P2 normal
Target Milestone: 4.9.1
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-06-12 16:21 UTC by Roland Dreier
Modified: 2014-06-30 14:26 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.10.0, 4.8.3
Known to fail:
Last reconfirmed: 2014-06-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Dreier 2014-06-12 16:21:40 UTC
The following code compiles fine with gcc 4.8 (and clang 3.4 for giggles).  With gcc 4.9 I get the error shown; Debian's gcc-snapshot version of 4.10 behaves the same way.

The non-template member function fix() is accepted by all compilers, but 4.9 rejects the template member function repair().  I don't know of any C++ language reason why the body of repair() should be treated differently.

~$ cat a.cpp
struct A {
        typedef int (A::*cont_func)();
        template <A::cont_func> void wait(int);
        int notify();

        void fix() { wait<&A::notify>(0); } // OK
        template <int> void repair() { wait<&A::notify>(0); }
};

~$ for CC in gcc-4.8 clang gcc-4.9; do echo "=== $CC ("`$CC --version`")" ===; $CC -Wall -Werror -c a.cpp && echo SUCCESS; echo; done ; gcc-4.9 -v -c a.cpp

=== gcc-4.8 (gcc-4.8 (Debian 4.8.3-2) 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 (Debian clang version 3.4.1-4 (tags/RELEASE_34/dot1-final) (based on LLVM 3.4.1) Target: x86_64-pc-linux-gnu Thread model: posix) ===
SUCCESS

=== gcc-4.9 (gcc-4.9 (Debian 4.9.0-5) 4.9.0 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.) ===
a.cpp: In member function ‘void A::repair()’:
a.cpp:7:58: error: no matching function for call to ‘A::wait(int)’
         template <int> void repair() { wait<&A::notify>(0); }
                                                          ^
a.cpp:7:58: note: candidate is:
a.cpp:3:38: note: template<int (A::* <anonymous>)()> void A::wait(int)
         template <A::cont_func> void wait(int);
                                      ^
a.cpp:3:38: note:   template argument deduction/substitution failed:
a.cpp:7:58: error: ‘&((A*)this)->*A::notify’ is not a valid template argument for type ‘int (A::*)()’
         template <int> void repair() { wait<&A::notify>(0); }
                                                          ^
a.cpp:7:58: error: it must be a pointer-to-member of the form ‘&X::Y’
a.cpp:7:58: error: could not convert template argument ‘&((A*)this)->*A::notify’ to ‘int (A::*)()’

Using built-in specs.
COLLECT_GCC=gcc-4.9
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.9.0-5' --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-libmudflap --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 --with-arch-32=i586 --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.0 (Debian 4.9.0-5) 
COLLECT_GCC_OPTIONS='-v' '-c' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.9/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -D_GNU_SOURCE a.cpp -quiet -dumpbase a.cpp -mtune=generic -march=x86-64 -auxbase a -version -o /tmp/ccBdykTy.s
GNU C++ (Debian 4.9.0-5) version 4.9.0 (x86_64-linux-gnu)
	compiled by GNU C version 4.9.0, GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.1
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++ (Debian 4.9.0-5) version 4.9.0 (x86_64-linux-gnu)
	compiled by GNU C version 4.9.0, GMP version 6.0.0, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b8ef2963d5911ef424cca776623bf2bd
a.cpp: In member function ‘void A::repair()’:
a.cpp:7:58: error: no matching function for call to ‘A::wait(int)’
         template <int> void repair() { wait<&A::notify>(0); }
                                                          ^
a.cpp:7:58: note: candidate is:
a.cpp:3:38: note: template<int (A::* <anonymous>)()> void A::wait(int)
         template <A::cont_func> void wait(int);
                                      ^
a.cpp:3:38: note:   template argument deduction/substitution failed:
a.cpp:7:58: error: ‘&((A*)this)->*A::notify’ is not a valid template argument for type ‘int (A::*)()’
         template <int> void repair() { wait<&A::notify>(0); }
                                                          ^
a.cpp:7:58: error: it must be a pointer-to-member of the form ‘&X::Y’
a.cpp:7:58: error: could not convert template argument ‘&((A*)this)->*A::notify’ to ‘int (A::*)()’
Comment 1 Daniel Krügler 2014-06-13 21:42:46 UTC
The error also occurs for 4.10.0 20140612 (experimental)
Comment 2 Jason Merrill 2014-06-16 11:50:46 UTC
Author: jason
Date: Mon Jun 16 11:50:14 2014
New Revision: 211704

URL: https://gcc.gnu.org/viewcvs?rev=211704&root=gcc&view=rev
Log:
	PR c++/61488
	* pt.c (check_valid_ptrmem_cst_expr): Fix for template context.

Added:
    trunk/gcc/testsuite/g++.dg/template/ptrmem28.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
Comment 3 Richard Biener 2014-06-26 12:48:44 UTC
Fixed on trunk sofar.
Comment 4 Jason Merrill 2014-06-30 12:37:09 UTC
Author: jason
Date: Mon Jun 30 12:36:37 2014
New Revision: 212145

URL: https://gcc.gnu.org/viewcvs?rev=212145&root=gcc&view=rev
Log:
	PR c++/61488
	* pt.c (check_valid_ptrmem_cst_expr): Fix for template context.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/g++.dg/template/ptrmem28.C
Modified:
    branches/gcc-4_9-branch/gcc/cp/ChangeLog
    branches/gcc-4_9-branch/gcc/cp/pt.c
Comment 5 Jason Merrill 2014-06-30 14:26:56 UTC
Fixed for 4.9.1.