public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28385]  New: templated function call goes awry
@ 2006-07-14 19:52 Colin dot McCabe at ecitele dot com
  2006-07-18 13:40 ` [Bug c++/28385] " bangerth at dealii dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Colin dot McCabe at ecitele dot com @ 2006-07-14 19:52 UTC (permalink / raw)
  To: gcc-bugs

I have compiled the following code under gcc 3.4.6, 4.0.2, and 4.1.1:
=========================================================
#include <iostream>

class Foo {
  public:
    template<typename T>
    void operator()(const T& fcn) {
        std::cout << "calling fcn()..." << std::endl;
        fcn();
    }
};

void bar() {
    std::cout << "bar()" << std::endl;
}

int main() {
    Foo myFoo;
    myFoo(bar);
    myFoo(&bar);
    return 0;
}
========================================================
Output for gcc 4.0.2 and 4.1.1:

calling bar()...
calling bar()...
bar()

Output for gcc 3.4.6:
calling bar()...
bar()
calling bar()...
bar()

Also, if you change 
    void operator()(const T& fcn) {
to 
    void operator()(const T fcn) {
It successfully makes both function calls on every version of gcc.

Everyone knows that in C, "&function_name" and "function_name" are generally
equivalent-- you can write:
  func_ptr_type* f = &function_name;
or 
  func_ptr_type* f = function_name;

So it is surprising to me that 
  myFoo(bar);
seems to behave differently than:
  myFoo(&bar);

I'm also surprised that there is no type error or other diagnostic message in
cases where code to call bar() is omitted.


-- 
           Summary: templated function call goes awry
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Colin dot McCabe at ecitele dot com


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


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

* [Bug c++/28385] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
@ 2006-07-18 13:40 ` bangerth at dealii dot org
  2006-07-18 13:51 ` [Bug c++/28385] [4.0/4.1/4.2 regression] " bangerth at dealii dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2006-07-18 13:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at dealii dot org  2006-07-18 13:40 -------
(In reply to comment #0)

> Everyone knows that in C, "&function_name" and "function_name" are generally
> equivalent-- you can write:
>   func_ptr_type* f = &function_name;
> or 
>   func_ptr_type* f = function_name;
> 
> So it is surprising to me that 
>   myFoo(bar);
> seems to behave differently than:
>   myFoo(&bar);

The difference is that C++ has references whereas C doesn't. 'bar' has type
'reference to function', whereas '&bar' is 'pointer to function'.

W.


-- 


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
  2006-07-18 13:40 ` [Bug c++/28385] " bangerth at dealii dot org
@ 2006-07-18 13:51 ` bangerth at dealii dot org
  2006-08-08 19:55 ` janis at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2006-07-18 13:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bangerth at dealii dot org  2006-07-18 13:51 -------
Independent of the previous question, I believe gcc is wrong.
There should be two calls to bar().

Confirmed.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
           Severity|normal                      |major
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.2 4.1.0
      Known to work|                            |3.4.6
           Priority|P3                          |P2
   Last reconfirmed|0000-00-00 00:00:00         |2006-07-18 13:51:33
               date|                            |
            Summary|templated function call goes|[4.0/4.1/4.2 regression]
                   |awry                        |templated function call goes
                   |                            |awry
   Target Milestone|---                         |4.0.4


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
  2006-07-18 13:40 ` [Bug c++/28385] " bangerth at dealii dot org
  2006-07-18 13:51 ` [Bug c++/28385] [4.0/4.1/4.2 regression] " bangerth at dealii dot org
@ 2006-08-08 19:55 ` janis at gcc dot gnu dot org
  2006-08-08 20:47 ` pcarlini at suse dot de
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: janis at gcc dot gnu dot org @ 2006-08-08 19:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from janis at gcc dot gnu dot org  2006-08-08 19:55 -------
A regression hunt on powerpc-linux identified this patch where a testcase based
on the submitter's test (see below) starts failing:

    http://gcc.gnu.org/viewcvs?view=rev&rev=95356

    r95356 | paolo | 2005-02-21 23:12:27 +0000 (Mon, 21 Feb 2005)

Paolo checked in the patch, but it's from Douglas Gregor.

Here's the test I used, compiled with -O2:

-------------------
extern "C" void abort (void);

int barcnt = 0;

class Foo {
  public:
    template<typename T>
    void operator()(const T& fcn) {
      fcn();
    }
};

void bar() {
  barcnt++;
}

int main() {
  Foo myFoo;
  myFoo(bar);
  myFoo(&bar);
  if (barcnt != 2)
    abort ();
  return 0;
}
-------------------


-- 

janis at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo at gcc dot gnu dot org


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (2 preceding siblings ...)
  2006-08-08 19:55 ` janis at gcc dot gnu dot org
@ 2006-08-08 20:47 ` pcarlini at suse dot de
  2006-08-16 21:19 ` jason at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pcarlini at suse dot de @ 2006-08-08 20:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pcarlini at suse dot de  2006-08-08 20:47 -------
Maybe Doug can help (certainly not me ;) ...


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dgregor at cs dot indiana
                   |                            |dot edu


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (3 preceding siblings ...)
  2006-08-08 20:47 ` pcarlini at suse dot de
@ 2006-08-16 21:19 ` jason at gcc dot gnu dot org
  2006-08-16 21:21 ` pcarlini at suse dot de
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-08-16 21:19 UTC (permalink / raw)
  To: gcc-bugs



-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |jason at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2006-07-18 13:51:33         |2006-08-16 21:19:01
               date|                            |


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (4 preceding siblings ...)
  2006-08-16 21:19 ` jason at gcc dot gnu dot org
@ 2006-08-16 21:21 ` pcarlini at suse dot de
  2006-08-17  0:51 ` jason at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pcarlini at suse dot de @ 2006-08-16 21:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pcarlini at suse dot de  2006-08-16 21:21 -------
Thanks Jason!


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|paolo at gcc dot gnu dot org|


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


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

* [Bug c++/28385] [4.0/4.1/4.2 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (5 preceding siblings ...)
  2006-08-16 21:21 ` pcarlini at suse dot de
@ 2006-08-17  0:51 ` jason at gcc dot gnu dot org
  2006-08-18 16:27 ` [Bug c++/28385] [4.0/4.1 " jason at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-08-17  0:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jason at gcc dot gnu dot org  2006-08-17 00:51 -------
Subject: Bug 28385

Author: jason
Date: Thu Aug 17 00:51:37 2006
New Revision: 116203

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116203
Log:
        PR c++/28385
        * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Ignore quals from template
        if arg is a function.

Added:
    trunk/gcc/testsuite/g++.dg/template/const1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c


-- 


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


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

* [Bug c++/28385] [4.0/4.1 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (6 preceding siblings ...)
  2006-08-17  0:51 ` jason at gcc dot gnu dot org
@ 2006-08-18 16:27 ` jason at gcc dot gnu dot org
  2006-08-18 16:28 ` jason at gcc dot gnu dot org
  2006-08-19  7:19 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-08-18 16:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2006-08-18 16:27 -------
Subject: Bug 28385

Author: jason
Date: Fri Aug 18 16:27:03 2006
New Revision: 116243

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116243
Log:
        PR c++/28385
        * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Ignore quals from template
        if arg is a function.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/template/const1.C
      - copied unchanged from r116203,
trunk/gcc/testsuite/g++.dg/template/const1.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/pt.c
    branches/gcc-4_0-branch/gcc/cp/search.c


-- 


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


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

* [Bug c++/28385] [4.0/4.1 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (7 preceding siblings ...)
  2006-08-18 16:27 ` [Bug c++/28385] [4.0/4.1 " jason at gcc dot gnu dot org
@ 2006-08-18 16:28 ` jason at gcc dot gnu dot org
  2006-08-19  7:19 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-08-18 16:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jason at gcc dot gnu dot org  2006-08-18 16:28 -------
Subject: Bug 28385

Author: jason
Date: Fri Aug 18 16:28:15 2006
New Revision: 116244

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116244
Log:
        PR c++/28385
        * pt.c (tsubst) [TEMPLATE_TYPE_PARM]: Ignore quals from template
        if arg is a function.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/const1.C
      - copied unchanged from r116203,
trunk/gcc/testsuite/g++.dg/template/const1.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/pt.c


-- 


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


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

* [Bug c++/28385] [4.0/4.1 regression] templated function call goes awry
  2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
                   ` (8 preceding siblings ...)
  2006-08-18 16:28 ` jason at gcc dot gnu dot org
@ 2006-08-19  7:19 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-08-19  7:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pinskia at gcc dot gnu dot org  2006-08-19 07:19 -------
Fixed.


-- 

pinskia at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-08-19  7:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-14 19:52 [Bug c++/28385] New: templated function call goes awry Colin dot McCabe at ecitele dot com
2006-07-18 13:40 ` [Bug c++/28385] " bangerth at dealii dot org
2006-07-18 13:51 ` [Bug c++/28385] [4.0/4.1/4.2 regression] " bangerth at dealii dot org
2006-08-08 19:55 ` janis at gcc dot gnu dot org
2006-08-08 20:47 ` pcarlini at suse dot de
2006-08-16 21:19 ` jason at gcc dot gnu dot org
2006-08-16 21:21 ` pcarlini at suse dot de
2006-08-17  0:51 ` jason at gcc dot gnu dot org
2006-08-18 16:27 ` [Bug c++/28385] [4.0/4.1 " jason at gcc dot gnu dot org
2006-08-18 16:28 ` jason at gcc dot gnu dot org
2006-08-19  7:19 ` 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).