Bug 45492 - G++ permits function-to-data pointer conversions with __extension__ in functions, but not function templates
Summary: G++ permits function-to-data pointer conversions with __extension__ in functi...
Status: RESOLVED DUPLICATE of bug 21385
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 00:29 UTC by Jim Blandy
Modified: 2012-05-29 11:52 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Blandy 2010-09-02 00:29:11 UTC
With trunk G++:

$ ~/gcc/bin/g++ --version
g++ (GCC) 4.6.0 20100901 (experimental)
Copyright (C) 2010 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.

$ cat fdc.cc
extern void cf();

// no warning
void *f() { return __extension__ (void *) cf; }

// warning:
// ISO C++ forbids casting between pointer-to-function and pointer-to-object
template<bool flag>
void *ft() { return __extension__ (void *) cf; }

template void *ft<true>();
$ LD_LIBRARY_PATH=$HOME/gcc/lib ~/gcc/bin/g++ -Wall -pedantic -c fdc.cc
fdc.cc: In function ‘void* ft() [with bool flag = true]’:
fdc.cc:11:25:   instantiated from here
fdc.cc:9:44: warning: ISO C++ forbids casting between pointer-to-function and pointer-to-object [enabled by default]

I would expect G++ to either complain about both casts, or neither; whether the code appears in a function template shouldn't matter.
Comment 1 Andrew Pinski 2010-09-02 00:30:28 UTC
Related to PR 21385.
Comment 2 Paolo Carlini 2012-05-29 11:52:52 UTC
It's the same issue.

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