public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39444]  New: ICE caused by default template argument
@ 2009-03-12 17:20 tortoise_74 at yahoo dot co dot uk
  2009-03-12 17:21 ` [Bug c++/39444] " tortoise_74 at yahoo dot co dot uk
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: tortoise_74 at yahoo dot co dot uk @ 2009-03-12 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

Compiling the following code causes an internal compiler error on both:
  gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux)
&
  gcc (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)

#include <string>
#include <typeinfo>

template<class FILTER, const std::string& filterName = std::string("") >
class Filter
{
public:
   virtual const std::string& getFilterName() const
   {
      static const std::string name = filterName;
      return name;
   }
};

void breakMe() 
{
   Filter<int> boo;
}

The output is:

g++    -c -o template.o template.cpp
template.cpp: In instantiation of ^[$-1òøFilter<int, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >(((const char*)""), ((const
std::allocator<char>&)((const std::allocator<char>*)(&
std::allocator<char>()))))>òù:
template.cpp:18:   instantiated from here
template.cpp:7: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.

Using a typeid in place of std::string("") for the default causes a more
cryptic

g++    -c -o template.o template.cpp
template.cpp: In instantiation of ‘Filter<int, ((const std::type_info*)(&
_ZTIi))->const char* std::type_info::name()>’:
template.cpp:45:   instantiated from here
template.cpp:34: sorry, unimplemented: call_expr cannot be mangled due to a
defect in the C++ ABI
template.cpp:34: sorry, unimplemented: call_expr cannot be mangled due to a
defect in the C++ ABI
template.cpp:45: sorry, unimplemented: call_expr cannot be mangled due to a
defect in the C++ ABI
template.cpp:45: sorry, unimplemented: call_expr cannot be mangled due to a
defect in the C++ ABI
template.cpp: In member function ‘const std::string& Filter<FILTER,
filterName>::getFilterName() const [with FILTER = int, const std::string&
filterName = ((const std::type_info*)(& _ZTIi))->std::type_info::name()]’:
template.cpp:45:   instantiated from here
template.cpp:38: sorry, unimplemented: call_expr cannot be mangled due to a
defect in the C++ ABI


-- 
           Summary: ICE caused by default template argument
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tortoise_74 at yahoo dot co dot uk
 GCC build triplet: x86_64-linux-redhat
  GCC host triplet: x86_64-linux-redhat
GCC target triplet: x86_64-linux-redhat


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


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

* [Bug c++/39444] ICE caused by default template argument
  2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
@ 2009-03-12 17:21 ` tortoise_74 at yahoo dot co dot uk
  2009-03-12 17:23 ` tortoise_74 at yahoo dot co dot uk
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tortoise_74 at yahoo dot co dot uk @ 2009-03-12 17:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from tortoise_74 at yahoo dot co dot uk  2009-03-12 17:21 -------
Created an attachment (id=17449)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17449&action=view)
ICE with arg = std::string("")


-- 


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


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

* [Bug c++/39444] ICE caused by default template argument
  2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
  2009-03-12 17:21 ` [Bug c++/39444] " tortoise_74 at yahoo dot co dot uk
@ 2009-03-12 17:23 ` tortoise_74 at yahoo dot co dot uk
  2009-03-12 18:34 ` tortoise_74 at yahoo dot co dot uk
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: tortoise_74 at yahoo dot co dot uk @ 2009-03-12 17:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from tortoise_74 at yahoo dot co dot uk  2009-03-12 17:23 -------
Created an attachment (id=17450)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17450&action=view)
"defect in the C++ ABI" message


-- 


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


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

* [Bug c++/39444] ICE caused by default template argument
  2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
  2009-03-12 17:21 ` [Bug c++/39444] " tortoise_74 at yahoo dot co dot uk
  2009-03-12 17:23 ` tortoise_74 at yahoo dot co dot uk
@ 2009-03-12 18:34 ` tortoise_74 at yahoo dot co dot uk
  2009-03-17 22:10 ` dodji at redhat dot com
  2009-04-16 20:50 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: tortoise_74 at yahoo dot co dot uk @ 2009-03-12 18:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from tortoise_74 at yahoo dot co dot uk  2009-03-12 18:34 -------
I should point out (as it is not obvious to the uninitiated) that this may not
be legal C++ as "A string literal cannot be used as a template argument". 
String literals have internal linkage. So string arguments can only be used if
they are declared extern.

The bug might be that gcc is not outputting this message but instead an ICE or
something about the ABI.

However, a std::string is not the same as a char* so a language lawyer might be
needed here. The bugs manifest as if the two are identical. 


-- 


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


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

* [Bug c++/39444] ICE caused by default template argument
  2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
                   ` (2 preceding siblings ...)
  2009-03-12 18:34 ` tortoise_74 at yahoo dot co dot uk
@ 2009-03-17 22:10 ` dodji at redhat dot com
  2009-04-16 20:50 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: dodji at redhat dot com @ 2009-03-17 22:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dodji at gcc dot gnu dot org  2009-03-17 22:10 -------
Subject: Re:   New: ICE caused by default template argument

FWIW, on gcc 4.3.2, I get the error:

test.cc: In function 'void breakMe()':
test.cc:17: error: a cast to a type other than an integral or
enumeration type cannot appear in a constant-expression
test.cc:17: error: template argument 2 is invalid
test.cc:17: error: invalid type in declaration before ';' token

The source listing annotated with line numbers is:
   1  #include <string>
     2  #include <typeinfo>
     3
     4  template<class FILTER, const std::string& filterName =
std::string("") >
     5  class Filter
     6  {
     7  public:
     8     virtual const std::string& getFilterName() const
     9     {
    10        static const std::string name = filterName;
    11        return name;
    12     }
    13  };
    14
    15  void breakMe()
    16  {
    17     Filter<int> boo;
    18  }
    19


-- 


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


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

* [Bug c++/39444] ICE caused by default template argument
  2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
                   ` (3 preceding siblings ...)
  2009-03-17 22:10 ` dodji at redhat dot com
@ 2009-04-16 20:50 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-16 20:50 UTC (permalink / raw)
  To: gcc-bugs

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



------- Comment #5 from pinskia at gcc dot gnu dot org  2009-04-16 20:50 -------
The trunk gives:
t.cc:18: error: a cast to a type other than an integral or enumeration type
cannot appear in a constant-expression
t.cc:18: error: template argument 2 is invalid
t.cc:18: error: invalid type in declaration before ‘;’ token

So does 4.4.0
So closing as fixed for 4.4.0


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |ice-on-invalid-code
         Resolution|                            |FIXED
   Target Milestone|---                         |4.4.0


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


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

end of thread, other threads:[~2009-04-16 20:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-12 17:20 [Bug c++/39444] New: ICE caused by default template argument tortoise_74 at yahoo dot co dot uk
2009-03-12 17:21 ` [Bug c++/39444] " tortoise_74 at yahoo dot co dot uk
2009-03-12 17:23 ` tortoise_74 at yahoo dot co dot uk
2009-03-12 18:34 ` tortoise_74 at yahoo dot co dot uk
2009-03-17 22:10 ` dodji at redhat dot com
2009-04-16 20:50 ` 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).