public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29927]  New: template instantiation with function type
@ 2006-11-21 16:06 s__nakayama at infoseek dot jp
  2006-11-21 17:07 ` [Bug c++/29927] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: s__nakayama at infoseek dot jp @ 2006-11-21 16:06 UTC (permalink / raw)
  To: gcc-bugs

Compile the following code and run it. It cause a segmentation fault.

template <class T>
void foo()
{
  T bar;
  bar();
}

int main()
{ 
  foo<int ()>();
  return 0;
}


-- 
           Summary: template instantiation with function type
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: s__nakayama at infoseek dot jp


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
@ 2006-11-21 17:07 ` pinskia at gcc dot gnu dot org
  2006-11-22  3:59 ` bangerth at dealii dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-11-21 17:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-11-21 17:07 -------
Confirmed.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid
   Last reconfirmed|0000-00-00 00:00:00         |2006-11-21 17:07:12
               date|                            |


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
  2006-11-21 17:07 ` [Bug c++/29927] " pinskia at gcc dot gnu dot org
@ 2006-11-22  3:59 ` bangerth at dealii dot org
  2006-11-22 14:57 ` s__nakayama at infoseek dot jp
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2006-11-22  3:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2006-11-22 03:59 -------
What exactly do you expect the code to do? 
  foo<int ()>();
leads to an instantiation of foo<T> with 
  T= int()()
i.e. reference to "no-arg function returning int". From
thereon I am a bit confused what exactly you intend to
do in foo()...

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
  2006-11-21 17:07 ` [Bug c++/29927] " pinskia at gcc dot gnu dot org
  2006-11-22  3:59 ` bangerth at dealii dot org
@ 2006-11-22 14:57 ` s__nakayama at infoseek dot jp
  2006-11-22 15:32 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: s__nakayama at infoseek dot jp @ 2006-11-22 14:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from s__nakayama at infoseek dot jp  2006-11-22 14:57 -------
(In reply to comment #2)
(In reply to comment #2)
> What exactly do you expect the code to do? 
>   foo<int ()>();
> leads to an instantiation of foo<T> with 
>   T= int()()
> i.e. reference to "no-arg function returning int". From
> thereon I am a bit confused what exactly you intend to
> do in foo()...

I expected that the compiler reject it. 
But Comeau compiler also accepted this code.
gcc 2.95.3 don't generate code that causes segmentation fault.(LINK error)
another test case:
following invalid code causes ICE.

template <class T>
void foo()
{
  T bar = 0;
  bar();
}

int main()
{ 
  foo<int ()>();
  return 0;
}


-- 


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
                   ` (2 preceding siblings ...)
  2006-11-22 14:57 ` s__nakayama at infoseek dot jp
@ 2006-11-22 15:32 ` bangerth at dealii dot org
  2006-11-23 14:35 ` s__nakayama at infoseek dot jp
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2006-11-22 15:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bangerth at dealii dot org  2006-11-22 15:31 -------
(In reply to comment #3)
> I expected that the compiler reject it. 
> But Comeau compiler also accepted this code.

As does icc.

I can't see why the code would be invalid if one accepts that
  T bar;
is the declaration of a function pointer 'bar'. In that case, you
simply have an invalid function pointer and calling it should yield
a segfault, just as you get.

Now, here's a different interpretation that icc actually takes: it says
that
  T bar;
is the declaration for a function with name and signature
  int bar();
and the code will yield a linker error when compiled.

In any case, can you clarify why exactly you think the code should be
rejected?

W.


-- 


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
                   ` (3 preceding siblings ...)
  2006-11-22 15:32 ` bangerth at dealii dot org
@ 2006-11-23 14:35 ` s__nakayama at infoseek dot jp
  2006-11-27  2:01 ` bangerth at dealii dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: s__nakayama at infoseek dot jp @ 2006-11-23 14:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from s__nakayama at infoseek dot jp  2006-11-23 14:34 -------
(In reply to comment #4)
> In any case, can you clarify why exactly you think the code should be
> rejected?


ISO 14882:2003 14.3.1 p3

>  If a declaration acquires a function type through a type dependent on a
>  template-parameter and this causes a declaration that does not use the
>  syntactic form of a function declarator to have function type, the
>  program is ill-formed.


-- 


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
                   ` (4 preceding siblings ...)
  2006-11-23 14:35 ` s__nakayama at infoseek dot jp
@ 2006-11-27  2:01 ` bangerth at dealii dot org
  2007-05-17  5:04 ` s__nakayama at infoseek dot jp
  2007-09-24 23:33 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2006-11-27  2:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from bangerth at dealii dot org  2006-11-27 02:00 -------
Excellent, this is exactly the quote that settles this. For 
reference, 14.3.1/3 comes with a (as usual non-normative) example:

  [Example:

     template<class T> struct A {
             static T t;
     };
     typedef int function();
     A<function> a;                  // ill-formed: would declare
                                     // A<function>::t
                                     // as a static member function

   --end example]

So both gcc and icc are wrong.

W.


-- 


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
                   ` (5 preceding siblings ...)
  2006-11-27  2:01 ` bangerth at dealii dot org
@ 2007-05-17  5:04 ` s__nakayama at infoseek dot jp
  2007-09-24 23:33 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: s__nakayama at infoseek dot jp @ 2007-05-17  5:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from s__nakayama at infoseek dot jp  2007-05-17 06:04 -------
Fixed already in 4.2.0.


-- 


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


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

* [Bug c++/29927] template instantiation with function type
  2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
                   ` (6 preceding siblings ...)
  2007-05-17  5:04 ` s__nakayama at infoseek dot jp
@ 2007-09-24 23:33 ` pcarlini at suse dot de
  7 siblings, 0 replies; 9+ messages in thread
From: pcarlini at suse dot de @ 2007-09-24 23:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pcarlini at suse dot de  2007-09-24 23:33 -------
Therefore, if I understand correctly, we want to reject the code and 4.2.0 was
already implementing that behavior. This is not a regression, we can close it
as fixed. If I'm mistaken, please reopen, thanks.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to work|                            |4.2.0
         Resolution|                            |FIXED


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


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

end of thread, other threads:[~2007-09-24 23:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-21 16:06 [Bug c++/29927] New: template instantiation with function type s__nakayama at infoseek dot jp
2006-11-21 17:07 ` [Bug c++/29927] " pinskia at gcc dot gnu dot org
2006-11-22  3:59 ` bangerth at dealii dot org
2006-11-22 14:57 ` s__nakayama at infoseek dot jp
2006-11-22 15:32 ` bangerth at dealii dot org
2006-11-23 14:35 ` s__nakayama at infoseek dot jp
2006-11-27  2:01 ` bangerth at dealii dot org
2007-05-17  5:04 ` s__nakayama at infoseek dot jp
2007-09-24 23:33 ` pcarlini at suse dot de

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).