public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17045] New: conflict between function template and class with same name
@ 2004-08-16  3:08 gccbugs at contacts dot eelis dot net
  2004-08-16  3:40 ` [Bug c++/17045] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gccbugs at contacts dot eelis dot net @ 2004-08-16  3:08 UTC (permalink / raw)
  To: gcc-bugs

The following code is rejected by GCC 3.4.1 :

  template <typename T> void f (T) {}

  template <typename T> void g () { f(T()); }

  namespace N
  {
    struct f {};
  }

  void h () { g<N::f>(); }

Error:

  t.cpp: In function `void g() [with T = N::f]':
  t.cpp:10:   instantiated from here
  t.cpp:7: error: `struct N::f' is not a function,
  t.cpp:1: error:   conflict with `template<class T> void f(T)'
  t.cpp:3: error:   in call to `f'

Comeau 4.3.3 accepts the code.

-- 
           Summary: conflict between function template and class with same
                    name
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gccbugs at contacts dot eelis dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/17045] conflict between function template and class with same name
  2004-08-16  3:08 [Bug c++/17045] New: conflict between function template and class with same name gccbugs at contacts dot eelis dot net
@ 2004-08-16  3:40 ` pinskia at gcc dot gnu dot org
  2004-08-16  4:12 ` gccbugs at contacts dot eelis dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-16  3:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-16 03:40 -------
Confirmed, what is happening is that GCC is deciding too early that T() will be a function call.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |rejects-valid
      Known to fail|                            |2.95.3 3.0.4 3.2.3 3.3.3
                   |                            |3.4.0 3.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-08-16 03:40:54
               date|                            |


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


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

* [Bug c++/17045] conflict between function template and class with same name
  2004-08-16  3:08 [Bug c++/17045] New: conflict between function template and class with same name gccbugs at contacts dot eelis dot net
  2004-08-16  3:40 ` [Bug c++/17045] " pinskia at gcc dot gnu dot org
@ 2004-08-16  4:12 ` gccbugs at contacts dot eelis dot net
  2004-08-16 14:53 ` bangerth at dealii dot org
  2004-12-21 13:15 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: gccbugs at contacts dot eelis dot net @ 2004-08-16  4:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gccbugs at contacts dot eelis dot net  2004-08-16 04:12 -------
I'm not convinced T() is the problem, because if I change f(T()); to "T x;
f(x);" the problem remains.

-- 


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


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

* [Bug c++/17045] conflict between function template and class with same name
  2004-08-16  3:08 [Bug c++/17045] New: conflict between function template and class with same name gccbugs at contacts dot eelis dot net
  2004-08-16  3:40 ` [Bug c++/17045] " pinskia at gcc dot gnu dot org
  2004-08-16  4:12 ` gccbugs at contacts dot eelis dot net
@ 2004-08-16 14:53 ` bangerth at dealii dot org
  2004-12-21 13:15 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2004-08-16 14:53 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-16 14:53 -------
What is really happening is that in the instantiation of ::f<N::f>, the 
compiler sees the call 
  f(T()); 
Since the argument T() is of type N::f, it has to look up the name 
of the function in both the global namespace and the namespace of 
the argument, i.e. N (Koenig lookup). It just happens to find the 
latter rather than the former. 
 
An example that may be a little less confusing about reusing names is this: 
--------------------- 
void h (...); 
 
template <typename T> void g () { T t;  h(t); } 
 
namespace N 
{ 
  struct S {}; 
  struct h; 
} 
 
void foo () { g<N::S>(); } 
----------------------- 
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ -c x.cc 
x.cc: In function `void g() [with T = N::S]': 
x.cc:11:   instantiated from here 
x.cc:8: error: `struct N::h' is not a function, 
x.cc:1: error:   conflict with `void h(...)' 
x.cc:3: error:   in call to `h' 
 
W. 

-- 


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


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

* [Bug c++/17045] conflict between function template and class with same name
  2004-08-16  3:08 [Bug c++/17045] New: conflict between function template and class with same name gccbugs at contacts dot eelis dot net
                   ` (2 preceding siblings ...)
  2004-08-16 14:53 ` bangerth at dealii dot org
@ 2004-12-21 13:15 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2004-12-21 13:15 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From redi at gcc dot gnu dot org  2004-12-21 13:15 -------
Dup of bug 17365 ?


-- 


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


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

end of thread, other threads:[~2004-12-21 13:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-16  3:08 [Bug c++/17045] New: conflict between function template and class with same name gccbugs at contacts dot eelis dot net
2004-08-16  3:40 ` [Bug c++/17045] " pinskia at gcc dot gnu dot org
2004-08-16  4:12 ` gccbugs at contacts dot eelis dot net
2004-08-16 14:53 ` bangerth at dealii dot org
2004-12-21 13:15 ` redi 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).