operators in namespaces

Mark Dixon mark@reachin.se
Sat Nov 14 14:14:00 GMT 1998


Hi,

  We are currently porting some SGI/Irix code to Windows NT, and
finding that EGCS is definately the best choice. We have managed
to port large portions of our software so far, including parts that use
partial template specialisation and other things that are definately
not supported by MS Visual C+-+-.

  We have, however, found two possible bugs that we have been able
to reproduce in small test cases. The first one we are not really sure
of what is going wrong, but it seems to be namespace and template
related.

---- bugs.c+-+- ----
namespace Foo +AHs-
  struct Bar +AHs- +AH0AOw-
  inline Bar operator+ACo-( const Bar +ACY-l, const float +ACY-r ) +AHs-
     return l+ADs-
  +AH0-
  template+ADw- class T +AD4-
    inline T operator+ACo-( const float +ACY-l, const T +ACY-r ) +AHs-
      return r +ACo- l+ADs-
  +AH0-
+AH0-

main() +AHs-
  Foo::Bar z+ADs-
  Foo::Bar y +AD0- 5 +ACo- z+ADs-
+AH0-
--------
bash-2.02+ACQ- g+-+- bugs.c+-+-
bugs.c+-+-: In function +AGA-struct ::Foo::Bar operator +ACoAPA-::Foo::Bar+AD4-(const float
+ACY-, const struct ::Foo::Bar +ACY-)':
bugs.c+-+-:15:   instantiated from here
bugs.c+-+-:9: +AGA-operator +ACo-(const float +ACY-, const float +ACY-)' must have an argument
of class or enumerated type


The second case is probably not a bug, but we are unsure of
the exact ANSI specification on this point. The following code
compiles under the MIPSPro compiler, but not EGCS. There
are one or two parts of our code where we need to forward
declare a class and declare it a friend, and allow the nested
classes to have access.

----bugs.c+-+----
class Bar+ADs-

class Foo +AHs-
  friend class Bar+ADs-
  int a+ADs-
+AH0AOw-

struct Bar +AHs-
  Foo f2+ADs-
  void foo+AF8-access2() +AHs- int b +AD0- f2.a+ADs- +AH0-
  struct Nested +AHs-
 Foo f+ADs-
 void foo+AF8-access() +AHs- int b +AD0- f.a+ADs- +AH0-
  +AH0AOw-
+AH0AOw-

main() +AHs-
+AH0-
-----------
bash-2.02+ACQ- g+-+- bugs.c+-+-
bugs.c+-+-: In method +AGA-void Bar::Nested::foo+AF8-access()':
bugs.c+-+-:31: member +AGA-a' is a private member of class +AGA-Foo'



Many thanks,
Mark Dixon,
ReachIn Technologies AB.






More information about the Gcc-bugs mailing list