public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18449] New: Problems when using function overload&templates across namespaces.
@ 2004-11-12 11:00 Jean-Paul dot Chaput at lip6 dot fr
  2004-11-12 11:03 ` [Bug c++/18449] " Jean-Paul dot Chaput at lip6 dot fr
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jean-Paul dot Chaput at lip6 dot fr @ 2004-11-12 11:00 UTC (permalink / raw)
  To: gcc-bugs

Hi there,


My apologies for not filling target triplet & build-triplet, I uses the stock
Fedora core 2 gcc-c++ package (3.3.3-7) with all packages updates.

Here is a self-contained source file (needs nothing but STL) which show the
problem. I have three namespaces (NS1, NS2 & NS3) and a GetString() function
which have overload for POD and non-POD types in NS1 & NS2. If there are
overload of GetString() for POD types in NS3, the overload of POD types
from other namesspaces seems to be not taken in account.


Anyway, thanks for developping that great compiler.

---- Source -------- Source -------- Source -------- Source --------
                                                                               
                                
# include  <string>
# include  <iostream>
# include  <iomanip>
# include  <sstream>
                                                                               
                                
                                                                               
                                
  using namespace std;
                                                                               
                                
                                                                               
                                
  // Characterics common to all tests :
  //
  // In namespace NS1 :
  //   - GetString for class type "Int&".
  //   - GetString for POD type "Char".
  //
  // In namespace NS2 :
  //   - GetString for class type "Long&".
  //   - NO GetString for any POD type.
                                                                               
                                
                                                                               
                                
# define  CHECK_1   0
  // CHECK_1 :
  //
  // In namespace NS1 :
  //   - GetString template for "Data*".
  //
  // In namespace NS3 :
  //   - No GetString of any kind.
  //
  // Result :
  //   - Works OK for types from NS1 & NS2.
  //   - Pointer template OK for types from NS1 & NS2.
                                                                               
                                
# if  CHECK_1
#   define  NS3_OVERLOAD_CLASS     0
#   define  NS3_PODIMPORT          0
#   define  NS1_TEMPLATE           1
# endif
                                                                               
                                
                                                                               
                                

# if  CHECK_2
#   define  NS3_OVERLOAD_CLASS     1
#   define  NS3_PODIMPORT          0
#   define  NS1_TEMPLATE           0
# endif
                                                                               
                                
                                                                               
                                
# define  CHECK_3   0
  // CHECK_3 :
  //
  // In namespace NS3 :
  //   - GetString overload for class type "Char&".
  //   - GetString "manual" importation of NS1::GetString(float).
  //
  // Result :
  //   - Works OK for class types from NS1, NS2 & NS3.
  //   - Uses manual importation for POD type float.
  //   -
                                                                               
                                
# if  CHECK_3
#   define  NS3_OVERLOAD_CLASS     1
#   define  NS3_PODIMPORT          1
#   define  NS1_TEMPLATE           0
# endif
                                                                               
                                
                                                                               
                                
# define  CHECK_4   0
  // CHECK_4 :
  //
  // In namespace NS1 :
  //   - GetString template for "Data*".
  //
  // In namespace NS3 :
  //   - GetString overload for class type "Char&".
  //   - GetString "manual" importation of NS1::GetString(float).
  //
  // Result :
  //   - Works OK for class types from NS1, NS2 & NS3.
  //   - Uses manual importation for POD type float.
  //   - Template seems to be ignored for types coming from
  //       namespaces other than NS1.

                                                                               
                                
# if  CHECK_4
#   define  NS3_OVERLOAD_CLASS     1
#   define  NS3_PODIMPORT          1
#   define  NS1_TEMPLATE           1
# endif
                                                                               
                                
                                                                               
                                
# define  CHECK_5   1
  // CHECK_5 :
  //
  // In namespace NS3 :
  //   - NO overload for of kind.
  //   - GetString "manual" importation of NS1::GetString(float).
  //
  // Result :
  //    - Works OK : overload is correctly handled for POD type float.
  //        (uses first the manual importation in NS3).
  //   - As in CHECK_4, Template seems to be ignored for types coming
  //       from namespaces other than NS1.
                                                                               
                                
# if  CHECK_5
#   define  NS3_OVERLOAD_CLASS     0
#   define  NS3_PODIMPORT          1
#   define  NS1_TEMPLATE           1
# endif
                                                                               
                                
                                                                               
                                                                               
                                                                
                                                                               
                                
  namespace NS1 {
                                                                               
                                
      class Int {
        private:
          int  _value;
        public:
          explicit Int ( int value ) : _value(value) { };
          int GetValue () const { return _value; };
      };
                                                                               
                                
      string  GetString ( const Int& data )
      {
        cout << setw(79) << right
             << "NS1::Getstring(const Int&)" << endl;
        ostringstream os;
        os << data.GetValue();
        return os.str();
      }
                                                                               
                                
      string GetString ( const float f )
      {
        cout << setw(79) << right
             << "NS1::Getstring(const float)" << endl;
        ostringstream os;
        os << f;
        return os.str();
      }
                                                                               
                                
# if NS1_TEMPLATE
      template<class Data>
        string GetString ( const Data* data ) {
          cout << setw(79) << right
               << "template<class Data>NS1::Getstring(const Data*)"
               << endl;
          return (data) ? GetString(*data) : "NULL";
        }
# endif
                                                                               
                                
  }

  namespace NS2 {
                                                                               
                                
      using namespace NS1;
                                                                               
                                
      class Long {
        private:
          long  _value;
        public:
          explicit Long ( long value ) : _value(value) { };
          long GetValue () const { return _value; };
      };
                                                                               
                                
      string  GetString ( const Long& data )
      {
        cout << setw(79) << right
             << "NS2::Getstring(const Long&)" << endl;
        ostringstream os;
        os << data.GetValue();
        return os.str();
      }
                                                                               
                                
  }
                                                                               
                                
                                                                               
                                                                               
                                                                
  namespace NS3 {
                                                                               
                                
     using namespace NS2;
                                                                               
                                
# if NS3_OVERLOAD_CLASS
      class Char {
        private:
          const char* _value;
        public:
          explicit Char ( const char* value ) : _value(value) { };
          const char* GetValue () const { return _value; };
      };
                                                                               
                                
      string  GetString ( const Char& data )
      {
        cout << setw(79) << right
             << "NS3::Getstring(const Char&)"
             << endl;
        ostringstream os;
        os << data.GetValue();
        return os.str();
      }
# endif
                                                                               
                                
# if NS3_PODIMPORT
      inline string GetString ( const float f ) {
        cout << setw(79) << right
             << "inline NS3::GetString(const float)"
             << endl;
        return NS1::GetString(f);
      }
# endif
                                                                               
                                      void  TheTest ( ostream& o )
      {
        Int    i(1);
        float  j =  2.0;
        Long   k(3);
# if NS3_OVERLOAD_CLASS
        Char  l("4");
# endif
                                                                               
                                
        o << "Checking Simple Overload :" << endl;
        o << "  GetString(Int)   := " << GetString(i) << endl;
        o << "  GetString(float) := " << GetString(j) << endl;
        o << "  GetString(Long)  := " << GetString(k) << endl;
# if NS3_OVERLOAD_CLASS
        o << "  GetString(Char)  := " << GetString(l) << endl;
# endif
                                                                               
                                
# if NS1_TEMPLATE
        o << "Checking Overload+Template :" << endl;
        o << "  GetString(Int*)   := " << GetString(&i) << endl;
        o << "  GetString(float*) := " << GetString(&j) << endl;
        o << "  GetString(Long*)  := " << GetString(&k) << endl;
# if NS3_OVERLOAD_CLASS
        o << "  GetString(Char*)  := " << GetString(&l) << endl;
# endif
# endif
      }
                                                                               
                                
  }
                                                                               
                                
                                                                               
                                
using namespace NS3;
                                                                               
                                
                                                                               
                                
int  main ( int argc, char* argv[] )
{
  TheTest ( cout );
                                                                               
                                
  return 0;
}

-- 
           Summary: Problems when using function overload&templates across
                    namespaces.
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Jean-Paul dot Chaput at lip6 dot fr
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-redhat-linux


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


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

* [Bug c++/18449] Problems when using function overload&templates across namespaces.
  2004-11-12 11:00 [Bug c++/18449] New: Problems when using function overload&templates across namespaces Jean-Paul dot Chaput at lip6 dot fr
@ 2004-11-12 11:03 ` Jean-Paul dot Chaput at lip6 dot fr
  2004-11-12 20:16 ` pinskia at gcc dot gnu dot org
  2004-11-12 22:52 ` Jean-Paul dot Chaput at lip6 dot fr
  2 siblings, 0 replies; 4+ messages in thread
From: Jean-Paul dot Chaput at lip6 dot fr @ 2004-11-12 11:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Jean-Paul dot Chaput at lip6 dot fr  2004-11-12 11:03 -------
Created an attachment (id=7528)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7528&action=view)
Test function overload across namespaces

Sorry to have also included the test file into the bug description.
But this is my first time with bugzilla...

-- 


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


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

* [Bug c++/18449] Problems when using function overload&templates across namespaces.
  2004-11-12 11:00 [Bug c++/18449] New: Problems when using function overload&templates across namespaces Jean-Paul dot Chaput at lip6 dot fr
  2004-11-12 11:03 ` [Bug c++/18449] " Jean-Paul dot Chaput at lip6 dot fr
@ 2004-11-12 20:16 ` pinskia at gcc dot gnu dot org
  2004-11-12 22:52 ` Jean-Paul dot Chaput at lip6 dot fr
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-12 20:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-12 20:16 -------
Not a bug, templates do really get added to namespaces by using if 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/18449] Problems when using function overload&templates across namespaces.
  2004-11-12 11:00 [Bug c++/18449] New: Problems when using function overload&templates across namespaces Jean-Paul dot Chaput at lip6 dot fr
  2004-11-12 11:03 ` [Bug c++/18449] " Jean-Paul dot Chaput at lip6 dot fr
  2004-11-12 20:16 ` pinskia at gcc dot gnu dot org
@ 2004-11-12 22:52 ` Jean-Paul dot Chaput at lip6 dot fr
  2 siblings, 0 replies; 4+ messages in thread
From: Jean-Paul dot Chaput at lip6 dot fr @ 2004-11-12 22:52 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From Jean-Paul dot Chaput at lip6 dot fr  2004-11-12 22:52 -------
(In reply to comment #2)
> Not a bug, templates do really get added to namespaces by using if 

Sorry to bother you again but there's something I don't get.
Forget about template, it was an additionnal test I've added.

Please run the check #2 (and disable check #5 wich is default in the
attachment I've supplied), it's the basic namespace+overload test.
If the behavior of g++ is OK, please could you tell me where I can
find a description of the standard.

I join a new attachment with only check #2 activated.

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


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


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

end of thread, other threads:[~2004-11-12 22:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-12 11:00 [Bug c++/18449] New: Problems when using function overload&templates across namespaces Jean-Paul dot Chaput at lip6 dot fr
2004-11-12 11:03 ` [Bug c++/18449] " Jean-Paul dot Chaput at lip6 dot fr
2004-11-12 20:16 ` pinskia at gcc dot gnu dot org
2004-11-12 22:52 ` Jean-Paul dot Chaput at lip6 dot fr

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