Bug 858351

Summary: segfault on compiling partial specialization code
Product: Red Hat Enterprise Linux 6 Reporter: takehiro iyatomi <iyatomi>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact: Miroslav Franc <mfranc>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.3CC: jason, law, mcermak, mfranc, mpolacek, ohudlick
Target Milestone: rc   
Target Release: 6.6   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: gcc-4.4.7-5.el6 Doc Type: Bug Fix
Doc Text:
Previously, GCC could crash on an invalid C++ code involving a partial specialization of a member of a partial specialization. The bug has been fixed and GCC now issues a translation-time error instead of crashing.
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-10-14 05:01:19 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1023566    
Attachments:
Description Flags
source code to reproduce the problem none

Description takehiro iyatomi 2012-09-18 18:22:16 UTC
Created attachment 614091 [details]
source code to reproduce the problem

Description of problem:
some kind of C++ template partial specialization code causes segfault
(see attachment file bug.cpp)


Version-Release number of selected component (if applicable):
Using built-in specs.
Target: x86_64-redhat-linux
コンフィグオプション: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
スレッドモデル: posix
gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) 


How reproducible:
always


Steps to Reproduce:
1. try to build attachment file bug.cpp with gcc (eg. gcc bug.cpp)
  

Actual results:
[iyatomi@localhost test]$ gcc bug.cpp -lstdc++
bug.cpp: In member function ‘void functional<R(), REFER>::set(FUNCTOR&) [with FUNCTOR = test, R = int, REFER = referer::nop]’:
bug.cpp:43:   instantiated from ‘functional<R(), REFER>::functional(FUNCTOR&) [with FUNCTOR = test, R = int, REFER = referer::nop]’
bug.cpp:75:   instantiated from here
bug.cpp:57: internal compiler error: セグメンテーション違反です


Expected results:
gcc should not cause segfault :P
at least it should print correct compile error message


Additional info:
if I move partial specialization code (functional<R (), REFER>::callee<R (*)(), REFER>) inside of the definition of class functional, this problem seems not to happen.

[iyatomi@localhost test]$ diff bug.cpp bug2.cpp                                              
39a40,47
>       template <typename _R, template <class T> class REF>
>       struct callee<_R (*)(), REF> {
>               typedef _R (*type)();
>               static inline void set(anyptr &p, type f) { p.fn = reinterpret_cast<void (*)()>(f); }
>               static inline type get(anyptr &p) { return reinterpret_cast<type>(p.fn); }
>               static inline R invoke(anyptr &p) { return get(p)(); }
>               static inline void destroy(anyptr &a) {}
>       };
57,64d64
< template <typename R, template <class T> class REFER>
< struct functional<R (), REFER>::callee<R (*)(), REFER> {
<       typedef R (*type)();
<       static inline void set(anyptr &p, type f) { p.fn = reinterpret_cast<void (*)()>(f); }
<       static inline type get(anyptr &p) { return reinterpret_cast<type>(p.fn); }
<       static inline R invoke(anyptr &p) { return get(p)(); }
<       static inline void destroy(anyptr &a) {}
< };
[iyatomi@localhost test]$ gcc bug2.cpp -lstdc++                                              
[iyatomi@localhost test]$ ./a.out 
result:1

Comment 2 Jason Merrill 2012-12-05 19:11:51 UTC
To be equivalent to the in-class version, your out-of-class partial specialization needs another template header.  So instead of

template <typename R, template <class T> class REFER>
struct functional<R (), REFER>::callee<R (*)(), REFER> {

you would have

template <typename R, template <class T> class REFER>
template <typename _R, template <class T> class REF>
struct functional<R (), REFER>::callee<_R (*)(), REF> {

Certainly G++ should give a more useful error message.

Comment 3 RHEL Program Management 2012-12-14 08:32:23 UTC
This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 10 errata-xmlrpc 2014-10-14 05:01:19 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1377.html