public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Overloaded function called from template.
@ 2005-01-20  5:24 corey taylor
  2005-01-20  9:44 ` Nathan Sidwell
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: corey taylor @ 2005-01-20  5:24 UTC (permalink / raw)
  To: gcc-help

Hello,

  I am bringing this question from graphics3D development (
http://www.graphics3d.com ).

  I did not want to flood the bug system with an unqualified report,
so if you could help me clarify if this is an issue.

  This happens only with g++ 3.4

  Simply put, calling an overloaded function from a template will fail
with no matching overload IF the overloaded function is declared after
the template.

  In everything up to g++ 3.4, the overloaded function was properly
found when the template was used.  Considering that the template is
typically defined in a header, we don't see why it is expecting
overloaded functions defined before that in 3.4 and never before.

  An example of the code flow:

  void overloadedFunc(const std::string& var) {

  }

  void overloadedFunc(int var) {
  }

--- templated code that calls overloadedFunc with template variable --

  void overloadedFunc(const SpecialClass& var) {
  }

--- Use the templated code with SpecialClass ----


If I can provide better information, or if you think this could be
filed as a bug-report, please reply.

Corey Taylor

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

* Re: Overloaded function called from template.
  2005-01-20  5:24 Overloaded function called from template corey taylor
@ 2005-01-20  9:44 ` Nathan Sidwell
       [not found] ` <6.2.0.14.2.20050120063353.022bfc90@iplan-mn.corp.adobe.com>
  2005-01-21 11:07 ` Lionel B
  2 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2005-01-20  9:44 UTC (permalink / raw)
  To: corey taylor; +Cc: gcc-help

corey taylor wrote:

>   Simply put, calling an overloaded function from a template will fail
> with no matching overload IF the overloaded function is declared after
> the template.

>   An example of the code flow:
you fail to provide a complete code example, so I can only guess at
what might be happening.  Are you sure the call is dependent?  If it
is not, it will be resolved at parse time, and therefore not see
the later declaration.  This is something that was corrected in 3.4.

Otherwise, without a full example, we cannot help further.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Fwd: Overloaded function called from template.
       [not found]   ` <2e393d08050120073168093847@mail.gmail.com>
@ 2005-01-20 16:03     ` corey taylor
  0 siblings, 0 replies; 4+ messages in thread
From: corey taylor @ 2005-01-20 16:03 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

(I'm not used to gmail, accidentally replied to Eljay only.)

Certainly.  I didn't know if you wanted code like that on the list at first.

The issue in question happens without namespaces, but there are in
there for purposes of testing what we saw in our code.

The same error occurs with the templated method, or templated class.
I call it an error because I did not see anything specific changed for
this in 3.4 *other* than the two-pass.  If that change *properly*
affects code like this, that's what I am here to find out.  If there
is a spec. note on this order.

corey


On Thu, 20 Jan 2005 06:34:27 -0600, Eljay Love-Jensen <eljay@adobe.com> wrote:
> Hi Corey,
>
> I was unable to reproduce your issue.
>
> Could you provide a short code example that demonstrates the issue?
>
> Thanks,
> --Eljay
>
> At 11:24 PM 1/19/2005, you wrote:
> >Hello,
> >
> >   I am bringing this question from graphics3D development (
> >http://www.graphics3d.com ).
> >
> >   I did not want to flood the bug system with an unqualified report,
> >so if you could help me clarify if this is an issue.
> >
> >   This happens only with g++ 3.4
> >
> >   Simply put, calling an overloaded function from a template will fail
> >with no matching overload IF the overloaded function is declared after
> >the template.
> >
> >   In everything up to g++ 3.4, the overloaded function was properly
> >found when the template was used.  Considering that the template is
> >typically defined in a header, we don't see why it is expecting
> >overloaded functions defined before that in 3.4 and never before.
> >
> >   An example of the code flow:
> >
> >   void overloadedFunc(const std::string& var) {
> >
> >   }
> >
> >   void overloadedFunc(int var) {
> >   }
> >
> >--- templated code that calls overloadedFunc with template variable --
> >
> >   void overloadedFunc(const SpecialClass& var) {
> >   }
> >
> >--- Use the templated code with SpecialClass ----
> >
> >
> >If I can provide better information, or if you think this could be
> >filed as a bug-report, please reply.
> >
> >Corey Taylor
>
>

[-- Attachment #2: overload.cpp --]
[-- Type: application/octet-stream, Size: 858 bytes --]


// Include wrapper class in a wrapper namespace with overloaded functions
// defined before wrapper class in global namespace.

#include "overload.h"

#include <iostream>

// Define a class to be used as the parameter for an overload 

namespace wrapperNS {

    class parameter {
    public:
        parameter() : a(1) {}
        int a;
    };

} // wrapperNS


// Define another overload of the function in global namespace

int overloadedFunc(const wrapperNS::parameter& c) {
    return c.a;
}

// Define a class that uses the wrapper class which calls the overloaded function

namespace wrapperNS {

    class callingClass {
    public:
        wrapper w;

        callingClass() {
            std::cout << w.callOverloaded(parameter()) << std::endl;;
        }
    };

}


// main function
int main() {

    wrapperNS::callingClass();

    return 0;

}

[-- Attachment #3: overload.h --]
[-- Type: application/octet-stream, Size: 524 bytes --]

#ifndef OVERLOAD_H
#define OVERLOAD_H

#include <string>

// Define some overloaded functions

int overloadedFunc(int a) {
   return a; 
}

int overloadedFunc(const std::string& b) {
    return strlen(b.c_str());
}


// Define a namespace for wrapper class

namespace wrapperNS {

// Define a class that calls overloadedFunc

    class wrapper {
    public:

        template<class T>
        int callOverloaded(const T& ref) {
           return ::overloadedFunc(ref);
        }

    };

} // wrapperNS

#endif // OVERLOAD_H

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

* Re: Overloaded function called from template.
  2005-01-20  5:24 Overloaded function called from template corey taylor
  2005-01-20  9:44 ` Nathan Sidwell
       [not found] ` <6.2.0.14.2.20050120063353.022bfc90@iplan-mn.corp.adobe.com>
@ 2005-01-21 11:07 ` Lionel B
  2 siblings, 0 replies; 4+ messages in thread
From: Lionel B @ 2005-01-21 11:07 UTC (permalink / raw)
  To: gcc-help

"corey taylor" wrote in message
news:2e393d0805011921247c06c57a@mail.gmail.com...
> Hello,
>
>   I am bringing this question from graphics3D development (
> http://www.graphics3d.com ).
>
>   I did not want to flood the bug system with an unqualified report,
> so if you could help me clarify if this is an issue.
>
>   This happens only with g++ 3.4
>
>   Simply put, calling an overloaded function from a template will fail
> with no matching overload IF the overloaded function is declared after
> the template.

/snip/

> If I can provide better information, or if you think this could be
> filed as a bug-report, please reply.

Please post minimal (potentially) *compilable* code that exhibits your
problem.

Regards,

-- 
Lionel B



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

end of thread, other threads:[~2005-01-21 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-20  5:24 Overloaded function called from template corey taylor
2005-01-20  9:44 ` Nathan Sidwell
     [not found] ` <6.2.0.14.2.20050120063353.022bfc90@iplan-mn.corp.adobe.com>
     [not found]   ` <2e393d08050120073168093847@mail.gmail.com>
2005-01-20 16:03     ` Fwd: " corey taylor
2005-01-21 11:07 ` Lionel B

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