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

             Bug #: 56095
           Summary: Crash casting function pointer as non-type template
                    argument
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: s...@zarbosoft.com


g++ crashes when trying to cast a function pointer to another function pointer
as a non-type template argument.  I get a strange error in 4.6.3, and 4.7.2
segfaults.

Platform: Ubuntu 12.04.1 LTS
uname -a: Linux cerberus 3.2.0-35-generic #55-Ubuntu SMP Wed Dec 5 17:42:16 UTC
2012 x86_64 x86_64 x86_64 GNU/Linux

Code (c.cxx):
int *a(void) { return 0; }
typedef void (*IntermediarySignature)(void);
template <IntermediarySignature b> void z(void) {}

int main(int argc, char **argv)
{
    z<(IntermediarySignature)a>();
    z<reinterpret_cast<IntermediarySignature>(a)>();
    return 0;
}

4.7 output:
> g++-4.7 -std=c++11 c.cxx 
c.cxx: In function ‘int main(int, char**)’:
c.cxx:7:30: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.7/README.Bugs> for instructions.
Preprocessed source stored into /tmp/cc8vdZAa.out file, please attach this to
your bugreport.

If line 7 is commented out (the c-style cast), there's a segfault on line 8.

4.6 output:
> g++ -std=c++0x c.cxx 
c.cxx: In function ‘int main(int, char**)’:
c.cxx:7:30: error: ‘(IntermediarySignature)a’ is not a valid template argument
for type ‘void (*)()’ because function ‘#‘nop_expr’ not supported by
dump_decl#<declaration error>’ has not external linkage
c.cxx:7:30: error: no matching function for call to ‘z()’
c.cxx:7:30: note: candidate is:
c.cxx:3:41: note: template<void (* b)()> void z()
c.cxx:8:48: error: ‘(IntermediarySignature)a’ is not a valid template argument
for type ‘void (*)()’ because function ‘#‘nop_expr’ not supported by
dump_decl#<declaration error>’ has not external linkage
c.cxx:8:48: error: no matching function for call to ‘z()’
c.cxx:8:48: note: candidate is:
c.cxx:3:41: note: template<void (* b)()> void z()

Reply via email to