[Bug c++/58184] New: Pointer to overloaded function is non-deduced context
aschepler at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Aug 17 18:51:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58184
Bug ID: 58184
Summary: Pointer to overloaded function is non-deduced context
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: aschepler at gmail dot com
Created attachment 30669
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30669&action=edit
Sample c++ code
The attached program is ill-formed, but g++ 4.8.1 compiles it with no warnings.
g++ -v
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)
No output from either command:
g++ -std=c++03 -pedantic -Wall -Wextra main.cpp
g++ -std=c++11 -pedantic -Wall -Wextra main.cpp
Template parameter U cannot be deduced in the expression using f. I believe
this is true in both C++03 and C++11, although C++11 states it more clearly.
[C++03 14.8.3/2 ; C++11 14.8.2.5/2]
Type deduction is done independently for each P/A pair, and the deduced
template argument values are then combined.
[C++03 14.8.2.4/16]
A template-argument can be deduced from a pointer to function or pointer to
member function argument if the set of overloaded functions does not contain
function templates and at most one of a set of overloaded functions provides a
unique match.
[C++11 14.8.2.1/6]
When P is a function type, pointer to function type, or pointer to member
function type:
- If the argument is an overload set containing one or more function
templates, the parameter is treated as a non-deduced context.
- If the argument is an overload set (not containing function templates),
trial argument deduction is attempted using each of the members of the set. If
deduction succeeds for only one of the overload set members, that member is
used as the argument value for the deduction. If deduction succeeds for more
than one member of the overload set the parameter is treated as a non-deduced
context.
[C++11 14.8.2.1/8]
Example:
// Ambiguous deduction causes the second function parameter to be a
// non-deduced context.
template <class T> int f(T, T (*p)(T));
int g(int);
char g(char);
int i = f(1, g); // calls f(int, int (*)(int))
[End Standard quotes.]
Note the final example from C++11 is essentially the same as my example, except
that there is no other template parameter to be deduced, so type deduction
still succeeds.
Also, the current behavior leads to some strange inconsistencies. The order of
function parameters generally plays no role in type deduction, but if you
reverse the order of f's parameters and arguments in my example, g++ will
reject it.
More information about the Gcc-bugs
mailing list