public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13089] New: bug using operator[] for a template class & ISO C++ standard
@ 2003-11-17 18:37 olivier dot despouys at rte-france dot com
  2003-11-17 19:04 ` [Bug c++/13089] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: olivier dot despouys at rte-france dot com @ 2003-11-17 18:37 UTC (permalink / raw)
  To: gcc-bugs

Hi there !

First of all, the context :
~>  uname -a
Linux machine 2.4.20-3-686 #1 Sat Jun 7 22:34:55 EST 2003 i686 GNU/Linux
~> g++ -v
Reading specs from
/logiciels/public/gcc-3.3.1/lib/gcc-lib/i686-pc-linux-gnu/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --prefix=/logiciels/public/gcc-3.3.1
Thread model: posix
gcc version 3.3.1


Now, the short piece of code :
---8<-------------------- BEGINNING OF foo.cc ------------------------------
#include <iostream>

template <class T, int N> class Array
{
  private :
    T t_ [N];

  public :
    Array (const T& t = T ()) {raz (t);};
    Array (const Array<T, N>& a) {
      *this = a;
    };
    Array<T, N>& operator= (const Array<T, N>& a) {
      if (this != &a)
        for (size_t i = 0; i < N; i++)
          t_ [i] = a [i];
      return *this;
    };
    ~Array () {};
    void raz (const T& t = T ()) {
      for (size_t i = 0; i < N; i++)
        t_ [i] = t;
    }
    T& operator [] (size_t n) {
      return t_ [n];
    };
    const T& operator [] (size_t n) const {
      return t_ [n];
    };
    operator const T* () const {
      return t_;
    };
};

int main ()
{
  const Array<float, 48> tabDef;
  float valDef = tabDef[0];

  return 0;
}
---8<-------------------------- END OF foo.cc -------------------------------


Now, this is what the compiler gives :
~> g++ -c foo.cc
foo.cc: In function `int main()':
foo.cc:39: error: ISO C++ says that `const T& Array<T, N>::operator[](unsigned 
   int) const [with T = float, int N = 48]' and `operator[]' are ambiguous even 
   though the worst conversion for the former is better than the worst 
   conversion for the latter
foo.cc:39: error: ISO C++ says that `const T& Array<T, N>::operator[](unsigned 
   int) const [with T = float, int N = 48]' and `operator[]' are ambiguous even 
   though the worst conversion for the former is better than the worst 
   conversion for the latter

To me, the reason given by the compiler is rather obscure. I do not see 
any rule in the ISO C++ standard refering to this kind of ambiguity.
Anyway, the most striking thing is that if I comment the "operator const T* 
() const" operator, the compiler does not complain anymore.

If this is no bug, it really looks like one...
Thanks in advance for your help !

Olivier Despouys

-- 
           Summary: bug using operator[] for a template class & ISO C++
                    standard
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: olivier dot despouys at rte-france dot com
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/13089] bug using operator[] for a template class & ISO C++ standard
  2003-11-17 18:37 [Bug c++/13089] New: bug using operator[] for a template class & ISO C++ standard olivier dot despouys at rte-france dot com
@ 2003-11-17 19:04 ` pinskia at gcc dot gnu dot org
  2003-11-18  5:11 ` pinskia at gcc dot gnu dot org
  2004-09-21 16:14 ` ext dot zxmultran021 at astrium dot eads dot net
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-17 19:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-11-17 19:04 -------
The mainline gives this error:
pr13089.cc: In function `int main()':
pr13089.cc:38: error: ISO C++ says that these are ambiguous, even though the worst conversion 
for the first is better than the worst conversion for the second:
pr13089.cc:27: note: candidate 1: const T& Array<T, N>::operator[](size_t) const [with T = float, 
int N = 48]
pr13089.cc:38: note: candidate 2: operator[](const float*, int) <built-in>
pr13089.cc:38: error: ISO C++ says that these are ambiguous, even though the worst conversion 
for the first is better than the worst conversion for the second:
pr13089.cc:27: note: candidate 1: const T& Array<T, N>::operator[](size_t) const [with T = float, 
int N = 48]
pr13089.cc:38: note: candidate 2: operator[](const float*, int) <built-in>

-- 


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


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

* [Bug c++/13089] bug using operator[] for a template class & ISO C++ standard
  2003-11-17 18:37 [Bug c++/13089] New: bug using operator[] for a template class & ISO C++ standard olivier dot despouys at rte-france dot com
  2003-11-17 19:04 ` [Bug c++/13089] " pinskia at gcc dot gnu dot org
@ 2003-11-18  5:11 ` pinskia at gcc dot gnu dot org
  2004-09-21 16:14 ` ext dot zxmultran021 at astrium dot eads dot net
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-18  5:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-11-18 05:11 -------
The error message is correct, see dup bug 3747 for more info.
Copied main stuff here:
13.3.1.2 is where this is explained.

*** This bug has been marked as a duplicate of 8316 ***

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


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


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

* [Bug c++/13089] bug using operator[] for a template class & ISO C++ standard
  2003-11-17 18:37 [Bug c++/13089] New: bug using operator[] for a template class & ISO C++ standard olivier dot despouys at rte-france dot com
  2003-11-17 19:04 ` [Bug c++/13089] " pinskia at gcc dot gnu dot org
  2003-11-18  5:11 ` pinskia at gcc dot gnu dot org
@ 2004-09-21 16:14 ` ext dot zxmultran021 at astrium dot eads dot net
  2 siblings, 0 replies; 4+ messages in thread
From: ext dot zxmultran021 at astrium dot eads dot net @ 2004-09-21 16:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ext dot zxmultran021 at astrium dot eads dot net  2004-09-21 16:14 -------
Hello,

I use g++ 3.3.3 to compile my application, and I encountered a problem :

src/OpePreparator.cc:2075: error: ISO C++ says that `int 
   Ptr<T>::operator!=(const T*) const [with T = C_OPL::Header_att]' and `
   operator!=' are ambiguous even though the worst conversion for the former is 
   better than the worst conversion for the latter

It seems that this kind of problem is known in the GCC database as the 13089 
bug (duplicate of 8316)

Can you confirm me in which release this bug is fixed ?

Thank you a lot


-- 


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


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

end of thread, other threads:[~2004-09-21 16:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-17 18:37 [Bug c++/13089] New: bug using operator[] for a template class & ISO C++ standard olivier dot despouys at rte-france dot com
2003-11-17 19:04 ` [Bug c++/13089] " pinskia at gcc dot gnu dot org
2003-11-18  5:11 ` pinskia at gcc dot gnu dot org
2004-09-21 16:14 ` ext dot zxmultran021 at astrium dot eads dot net

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