public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39018]  New: Cannot take address of template function
@ 2009-01-29 13:25 hniksic at gmail dot com
  2009-01-30  0:21 ` [Bug c++/39018] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: hniksic at gmail dot com @ 2009-01-29 13:25 UTC (permalink / raw)
  To: gcc-bugs

The following code fails to compile under g++ 4.3.2:

class Bar {};

template<int N>
class Foo {
  double val[N];
};

template<int N>
void fun(Foo<N>* ptr) {
}

typedef void (*T)(Bar*);

T funptr = (T) &fun<2>;

The error message is:

$ g++ -c a.cc
a.cc:14: error: address of overloaded function with no contextual type
information

I don't know if the standard allows this, but it looks like it should be
allowed to take the address of a templated function, because it works in other
contexts (see below).  It seems unambiguous because with foo<2> we a specific
variant of the function is requested.  Intel's C++ compiler (icpc versions 9.1
and 10.1) accepts it.

It is possible to work around this error by providing "contextual type
information", although how to do that is not immediately obvious to everyone. 
The workaround that worked for me is to replace the last line with:

typedef void (*U)(Foo<2>*);
T funptr = (T) (U) &fun<2>;

which compiles without errors or warnings.

The error is similar to bug 29143, but I don't think it's a dup.  In that case,
the "contextual type information" is present, but apparently ignored by the
compiler.  In this case, context doesn't help with type determination, but it
shouldn't be necessary since foo<2> uniquely identifies the function.

Detailed version information:

$ g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu11'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3
--program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug
--enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu11)


-- 
           Summary: Cannot take address of template function
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hniksic at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39018


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/39018] Cannot take address of template function
  2009-01-29 13:25 [Bug c++/39018] New: Cannot take address of template function hniksic at gmail dot com
@ 2009-01-30  0:21 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-30  0:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2009-01-30 00:21 -------
Yes this is a known bug, please see PR 11407.

*** This bug has been marked as a duplicate of 11407 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39018


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-30  0:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-29 13:25 [Bug c++/39018] New: Cannot take address of template function hniksic at gmail dot com
2009-01-30  0:21 ` [Bug c++/39018] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).