public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40808]  New: member template specialization causes ICE
@ 2009-07-20  6:13 mark at austrics dot com dot au
  2009-08-25 14:17 ` [Bug c++/40808] [4.4/4.5 regression] " bangerth at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: mark at austrics dot com dot au @ 2009-07-20  6:13 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3416 bytes --]

Hi,

The following short code example produces an internal
compiler error with g++ 4.4.0.

struct Void {};

template <class R> struct FunType {
  typedef R ResultType;
};

struct WrongNumberOfSigArgs {};

template <typename R> struct CFunType {
  template <class Dummy1=Void, class Dummy2=Void> struct Sig : public
FunType<WrongNumberOfSigArgs> {};
  template <class Dummy> struct Sig<Void,Dummy> : public FunType<R> {};
};

struct Dummy {
  template <typename F> typename F::template Sig<>::ResultType operator()(F
const& f) const {
    return typename F::template Sig<>::ResultType(0);
  }
};

struct Gen: public CFunType<int> {
  int operator()() const {return 0;}
  Gen() {}
};

int myfunction() {
  return Dummy()(Gen());
}

int main() {
  myfunction();
}

I believe the above code is invalid.  But g++ should
stop with an error report rather than an internal
compiler error.  To make the code valid, in Dummy,
replace the two instances of Sig<> with Sig<Void>.

(With g++ 4.3.3 the code compiles fine -- which it 
shouldn't -- and seems to choose the wrong member 
template.)

The commandline I ran, and associated output is as follows.

$ LD_LIBRARY_PATH=/usr6/ausdev/32/gcc/lib: /usr6/ausdev/32/gcc/bin/g++ -v
templatebug.cc 
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/usr6/ausdev/32/gcc
--enable-threads=posix --enable-__cxa_atexit --enable-languages=c,c++
--with-gmp=/usr6/ausdev/tools/build/gmp
--with-mpfr=/usr6/ausdev/tools/build/mpfr --with-gnu-as
--with-as=/usr6/ausdev/32/gcc/bin/as
Thread model: posix
gcc version 4.4.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
 /usr6/ausdev/32/gcc/libexec/gcc/i686-pc-linux-gnu/4.4.0/cc1plus -quiet -v
-D_GNU_SOURCE templatebug.cc -quiet -dumpbase templatebug.cc -mtune=generic
-auxbase templatebug -version -o /tmp/ccKj2izO.s
ignoring nonexistent directory
"/usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../../include/c++/4.4.0

/usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../../include/c++/4.4.0/i686-pc-linux-gnu

/usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/../../../../include/c++/4.4.0/backward
 /usr/local/include
 /usr6/ausdev/32/gcc/include
 /usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/include
 /usr6/ausdev/32/gcc/lib/gcc/i686-pc-linux-gnu/4.4.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.4.0 (i686-pc-linux-gnu)
        compiled by GNU C version 4.4.0, GMP version 4.2.4, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cdc0e2c063f6091375cab171c4ed59f5
templatebug.cc: In function ‘int myfunction()’:
templatebug.cc:26: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


-- 
           Summary: member template specialization causes ICE
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mark at austrics dot com dot au


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
@ 2009-08-25 14:17 ` bangerth at gmail dot com
  2009-08-25 15:48 ` jsm28 at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: bangerth at gmail dot com @ 2009-08-25 14:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at gmail dot com  2009-08-25 14:16 -------
Confirmed. An ICE. I haven't checked the accepts-invalid part.


-- 

bangerth at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at gmail dot com
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-08-25 14:16:58
               date|                            |
            Summary|member template             |[4.4/4.5 regression] member
                   |specialization causes ICE   |template specialization
                   |                            |causes ICE


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
  2009-08-25 14:17 ` [Bug c++/40808] [4.4/4.5 regression] " bangerth at gmail dot com
@ 2009-08-25 15:48 ` jsm28 at gcc dot gnu dot org
  2009-08-31 21:52 ` mmitchel at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2009-08-25 15:48 UTC (permalink / raw)
  To: gcc-bugs



-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.4.2


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
  2009-08-25 14:17 ` [Bug c++/40808] [4.4/4.5 regression] " bangerth at gmail dot com
  2009-08-25 15:48 ` jsm28 at gcc dot gnu dot org
@ 2009-08-31 21:52 ` mmitchel at gcc dot gnu dot org
  2009-10-15 12:58 ` jakub at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2009-08-31 21:52 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
                   ` (2 preceding siblings ...)
  2009-08-31 21:52 ` mmitchel at gcc dot gnu dot org
@ 2009-10-15 12:58 ` jakub at gcc dot gnu dot org
  2009-10-23 10:58 ` dodji at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-10-15 12:58 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.4.2                       |4.4.3


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
                   ` (3 preceding siblings ...)
  2009-10-15 12:58 ` jakub at gcc dot gnu dot org
@ 2009-10-23 10:58 ` dodji at gcc dot gnu dot org
  2009-10-23 18:08   ` Dodji Seketeli
  2009-10-23 21:33 ` dodji at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: dodji at gcc dot gnu dot org @ 2009-10-23 10:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dodji at gcc dot gnu dot org  2009-10-23 10:58 -------
I am not sure the example is invalid.

The Dummy()(Gen()) call expression obviously selects the operator "template
<typename F> typename F::template Sig<>::ResultType operator()(F const& f)
const" in Dummy.

I believe the critical question is the following:

In:

~=~
template <typename R> struct CFunType {                                         
  template <class Dummy1=Void, class Dummy2=Void>
  struct Sig: public FunType<WrongNumberOfSigArgs>
  {
  };//#1

  template <class Dummy>
  struct Sig<Void,Dummy> : public FunType<R>
  {
  };//#2
};
~=~

Which Sig template is instantiated by "typename F::template Sig<>" ? Is it //#1
or //#2 ?

I think Sig<> matches the template #1 (as in Sig<void,void>) which is the
primary template. But then, the best specialization of #1 is selected by the
compiler. The arguments of that specialization are deduced from the arguments
of the primary template. The <void,void> argument list used to match the
primary template #1 is compatible with the parameters of the specialization #2.
So in the end it's #2 that is going to be instantiated.

The relevant parts of the C++ spec are, I believe, the following:

[temp.class.spec]
7. "Partial specialization declarations themselves are not found by name
lookup. Rather, when the primary template name is used, any previously-declared
partial specializations of the primary template are also considered."

[temp.class.spec.match]
1. "When a class template is used in a context that requires an instantiation
of the class, it is necessary to determine whether the instantiation is to be
generated using the primary template or one of the partial specializations.
This is done by matching the template arguments of the class template
specialization with the template argument lists of the partial
specializations."

That being said, the crash seems to happens later during the mangling of the
operator "template <typename F> typename F::template Sig<>::ResultType
operator()(F const& f) const", precisely on the Sig<> template-id because the
mangling code doesn't expect the template argument list to be empty.


-- 

dodji at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dodji at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2009-08-25 14:16:58         |2009-10-23 10:58:13
               date|                            |


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


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

* Re: [Bug c++/40808] [4.4/4.5 regression] member template  specialization causes ICE
  2009-10-23 10:58 ` dodji at gcc dot gnu dot org
@ 2009-10-23 18:08   ` Dodji Seketeli
  0 siblings, 0 replies; 10+ messages in thread
From: Dodji Seketeli @ 2009-10-23 18:08 UTC (permalink / raw)
  To: gcc-bugs

Posted a patch at http://gcc.gnu.org/ml/gcc-patches/2009-10/msg01469.html

-- 
Dodji Seketeli
Red Hat


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
                   ` (4 preceding siblings ...)
  2009-10-23 10:58 ` dodji at gcc dot gnu dot org
@ 2009-10-23 21:33 ` dodji at gcc dot gnu dot org
  2009-10-23 21:39 ` dodji at gcc dot gnu dot org
  2009-10-23 21:43 ` dodji at gcc dot gnu dot org
  7 siblings, 0 replies; 10+ messages in thread
From: dodji at gcc dot gnu dot org @ 2009-10-23 21:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from dodji at gcc dot gnu dot org  2009-10-23 21:32 -------
Subject: Bug 40808

Author: dodji
Date: Fri Oct 23 21:32:35 2009
New Revision: 153516

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153516
Log:
Fix for PR c++/40808

gcc/cp/ChangeLog:

        PR c++/40808
        * mangle.c (write_template_args): Allow mangling of empty template
        argument list. Updated function comments.

gcc/testsuite/ChangeLog:

        PR c++/40808
        * g++.dg/abi/mangle33.C: New test

Added:
    branches/gcc-4_4-branch/gcc/testsuite/g++.dg/abi/mangle34.C
Modified:
    branches/gcc-4_4-branch/gcc/cp/ChangeLog
    branches/gcc-4_4-branch/gcc/cp/mangle.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
                   ` (5 preceding siblings ...)
  2009-10-23 21:33 ` dodji at gcc dot gnu dot org
@ 2009-10-23 21:39 ` dodji at gcc dot gnu dot org
  2009-10-23 21:43 ` dodji at gcc dot gnu dot org
  7 siblings, 0 replies; 10+ messages in thread
From: dodji at gcc dot gnu dot org @ 2009-10-23 21:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dodji at gcc dot gnu dot org  2009-10-23 21:39 -------
Subject: Bug 40808

Author: dodji
Date: Fri Oct 23 21:38:50 2009
New Revision: 153517

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153517
Log:
Fix for PR c++/40808

gcc/cp/ChangeLog:

        PR c++/40808
        * mangle.c (write_template_args): Allow mangling of empty template
        argument list. Updated function comments.

gcc/testsuite/ChangeLog:

        PR c++/40808
        * g++.dg/abi/mangle34.C: New test

Added:
    trunk/gcc/testsuite/g++.dg/abi/mangle34.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/mangle.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/40808] [4.4/4.5 regression] member template specialization causes ICE
  2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
                   ` (6 preceding siblings ...)
  2009-10-23 21:39 ` dodji at gcc dot gnu dot org
@ 2009-10-23 21:43 ` dodji at gcc dot gnu dot org
  7 siblings, 0 replies; 10+ messages in thread
From: dodji at gcc dot gnu dot org @ 2009-10-23 21:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from dodji at gcc dot gnu dot org  2009-10-23 21:42 -------
Fixed in 4.4 and 4.5


-- 

dodji at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2009-10-23 21:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-20  6:13 [Bug c++/40808] New: member template specialization causes ICE mark at austrics dot com dot au
2009-08-25 14:17 ` [Bug c++/40808] [4.4/4.5 regression] " bangerth at gmail dot com
2009-08-25 15:48 ` jsm28 at gcc dot gnu dot org
2009-08-31 21:52 ` mmitchel at gcc dot gnu dot org
2009-10-15 12:58 ` jakub at gcc dot gnu dot org
2009-10-23 10:58 ` dodji at gcc dot gnu dot org
2009-10-23 18:08   ` Dodji Seketeli
2009-10-23 21:33 ` dodji at gcc dot gnu dot org
2009-10-23 21:39 ` dodji at gcc dot gnu dot org
2009-10-23 21:43 ` dodji 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).