Fun with error messages

Discussion in 'C++' started by Steven T. Hatton, Oct 9, 2004.

  1. One think I really dislike about the (default?) behavior of gcc is the way
    it prints errors to console. This is one such report:

    cd /home/hattons/code/c++/sth/vmath/test/ # -*-compilation-*-
    Entering directory `/home/hattons/code/c++/sth/vmath/test/'
    g++ -o testMatrix3 testMatrix3.cc -I/home/hattons/code/c++
    In file included from Matrix3Test.hh:4,
    from testMatrix3.cc:1:
    /home/hattons/code/c++/sth/vmath/Matrix3.hh:141: error: prototype for `const
    sth::vmath::IndexedReference<T, sth::vmath::Matrix3<T>::ORDER>&
    sth::vmath::Matrix3<T>::eek:perator[](const unsigned int&) const' does not
    match any in class `sth::vmath::Matrix3<T>'
    /home/hattons/code/c++/sth/vmath/Matrix3.hh:96: error: candidate is: const
    sth::vmath::IndexedReference<T, sth::vmath::Matrix3<T>::ORDER>&
    sth::vmath::Matrix3<T>::eek:perator[](const unsigned int&) const
    /home/hattons/code/c++/sth/vmath/Matrix3.hh:141: error: template definition
    of
    non-template `const sth::vmath::IndexedReference<T,
    sth::vmath::Matrix3<T>::ORDER>& sth::vmath::Matrix3<T>::eek:perator[](const
    unsigned int&) const'

    Compilation exited abnormally with code 1 at Fri Oct 8 19:32:56

    Now for the fun part. Read the message closely. What it boils down to is
    this:

    The first line is wrong. You should have used the second line:
    IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::eek:perator[](int&)
    IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::eek:perator[](int&)

    Now here's what the problem was. I have a static const unsigned ORDER = 3
    in Matrix3<T>. When I try to use that as a template parameter in the
    definition of a member function the compiler gets confused. Likewise if I
    try to use an enum. And I did qualify it where I used it outside the class
    definition.

    Anybody want to try and explain /that/?

    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
     
    Steven T. Hatton, Oct 9, 2004
    #1
    1. Advertising

  2. Steven T. Hatton

    Mike Wahler Guest

    Re: [OT, redir] Fun with error messages

    "Steven T. Hatton" <> wrote in message
    news:...
    > One think I really dislike about the (default?) behavior of gcc is the way
    > it prints errors to console. This is one such report:
    >
    > cd /home/hattons/code/c++/sth/vmath/test/ # -*-compilation-*-
    > Entering directory `/home/hattons/code/c++/sth/vmath/test/'
    > g++ -o testMatrix3 testMatrix3.cc -I/home/hattons/code/c++
    > In file included from Matrix3Test.hh:4,
    > from testMatrix3.cc:1:
    > /home/hattons/code/c++/sth/vmath/Matrix3.hh:141: error: prototype for

    `const
    > sth::vmath::IndexedReference<T, sth::vmath::Matrix3<T>::ORDER>&
    > sth::vmath::Matrix3<T>::eek:perator[](const unsigned int&) const' does not
    > match any in class `sth::vmath::Matrix3<T>'
    > /home/hattons/code/c++/sth/vmath/Matrix3.hh:96: error: candidate is: const
    > sth::vmath::IndexedReference<T, sth::vmath::Matrix3<T>::ORDER>&
    > sth::vmath::Matrix3<T>::eek:perator[](const unsigned int&) const
    > /home/hattons/code/c++/sth/vmath/Matrix3.hh:141: error: template

    definition
    > of
    > non-template `const sth::vmath::IndexedReference<T,
    > sth::vmath::Matrix3<T>::ORDER>&

    sth::vmath::Matrix3<T>::eek:perator[](const
    > unsigned int&) const'
    >
    > Compilation exited abnormally with code 1 at Fri Oct 8 19:32:56
    >
    > Now for the fun part. Read the message closely. What it boils down to is
    > this:
    >
    > The first line is wrong. You should have used the second line:
    > IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::eek:perator[](int&)
    > IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::eek:perator[](int&)
    >
    > Now here's what the problem was. I have a static const unsigned ORDER = 3
    > in Matrix3<T>. When I try to use that as a template parameter in the
    > definition of a member function the compiler gets confused. Likewise if I
    > try to use an enum. And I did qualify it where I used it outside the

    class
    > definition.
    >
    > Anybody want to try and explain /that/?


    Not here. Here we discuss the language, not the operation
    or idiosyncracies of any particular implementation, nor the
    deciphering of diagnostic messages. The language does not
    mandate any particular form for diagnostic messages, only
    that 'a diagnostic' be issued upon encountering certain language
    violations. E.g. if you supply the wrong number of arguments to
    a function, it's valid for a compiler to complain: "your dog
    has fleas". If you're unhappy with the behavior of a compiler
    your recourses are to complain to the vendor, or use (or create)
    something else.

    I have many times seen folks deride a compiler (or other piece
    of software), but none has ever claimed to be able to create
    anything superior (I've taken to calling this the "Microsoft
    Windows Syndrome". There, I feel better now. :)

    I think you've been reading and posting here long enough to realize
    that your message is not topical here. If you want to pursue this,
    please take it to a gcc group or mailing list.

    www.gcc.gnu.org


    -Mike
     
    Mike Wahler, Oct 9, 2004
    #2
    1. Advertising

  3. Re: [OT, redir] Fun with error messages

    Mike Wahler wrote:

    > I think you've been reading and posting here long enough to realize
    > that your message is not topical here. If you want to pursue this,
    > please take it to a gcc group or mailing list.
    >
    > www.gcc.gnu.org
    >
    >
    > -Mike


    Why don't you address the part that /is/ about the language rather than
    trying to play c.l.c++ policeman? Here it is again for your convenience:

    Now here's what the problem was.  I have a static const unsigned ORDER = 3
    in Matrix3<T>.  When I try to use that as a template parameter in the
    definition of a member function the compiler gets confused.  Likewise if I
    try to use an enum.  And I did qualify it where I used it outside the class
    definition.

    Anybody want to try and explain /that/?
    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
     
    Steven T. Hatton, Oct 9, 2004
    #3
  4. Re: [OT, redir] Fun with error messages

    "Steven T. Hatton" <> wrote...
    > [...]
    > Now here's what the problem was. I have a static const unsigned ORDER = 3
    > in Matrix3<T>. When I try to use that as a template parameter in the
    > definition of a member function the compiler gets confused. Likewise if I
    > try to use an enum. And I did qualify it where I used it outside the class
    > definition.
    >
    > Anybody want to try and explain /that/?


    Can you use C++ to show the problem instead of trying to explain
    in English? Many of us here understand C++ better than English,
    you know.

    So:

    #include <iostream>

    namespace sth {
    namespace vmath {
    template<class T> class Matrix3 {
    static const unsigned ORDER = 3;
    public:
    template<unsigned N> void foo();
    };

    template<class T> template <unsigned N>
    void Matrix3<T>::foo() {
    // who cares
    for (int i = 0; i < ORDER; ++i)
    std::cout << "beep!";
    }
    }
    }

    int main() {
    sth::vmath::Matrix3<double> m;
    m.foo<2>();
    }

    Is that something you have a problem with? Comeau compiles it fine.
    G++ v 3.2.2 does just as well. If that's not it, how about reading
    the FAQ for a change? 5.8 should be right about what you need.

    V
     
    Victor Bazarov, Oct 9, 2004
    #4
  5. Re: [OT, redir] Fun with error messages

    Victor Bazarov wrote:

    > "Steven T. Hatton" <> wrote...
    >> [...]
    >> Now here's what the problem was. I have a static const unsigned ORDER = 3
    >> in Matrix3<T>. When I try to use that as a template parameter in the
    >> definition of a member function the compiler gets confused. Likewise if I
    >> try to use an enum. And I did qualify it where I used it outside the
    >> class definition.
    >>
    >> Anybody want to try and explain /that/?

    >
    > Can you use C++ to show the problem instead of trying to explain
    > in English? Many of us here understand C++ better than English,
    > you know.


    #include <iostream>
    //#define BROKEN
    #ifndef BROKEN

    #define REDRO 3
    #define REDRO2 REDRO

    #else

    #define REDRO ORDER
    #define REDRO2 C<T>::ORDER

    #endif

    namespace sth{
    template <typename T, unsigned N>
    struct S
    {
    S():n(N){}
    T n;
    std::eek:stream& print(std::eek:stream& out) const
    {
    return out << "The value of n is:" << n << "\n";
    }
    };

    template<typename T>
    class C {
    public:
    static const unsigned ORDER=3;

    const S<T, REDRO>& gimmie_s() const;

    protected:
    S<T, REDRO> _s;

    };

    template <typename T>
    const S<T, REDRO2>& C<T>::gimmie_s() const
    {
    return _s;
    }
    }


    int main()
    {
    sth::C<float> c;
    c.gimmie_s().print(std::cout);
    }

    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
     
    Steven T. Hatton, Oct 9, 2004
    #5
  6. Re: [OT, redir] Fun with error messages

    "Steven T. Hatton" <> wrote...
    > Victor Bazarov wrote:
    >
    >> "Steven T. Hatton" <> wrote...
    >>> [...]
    >>> Now here's what the problem was. I have a static const unsigned ORDER =
    >>> 3
    >>> in Matrix3<T>. When I try to use that as a template parameter in the
    >>> definition of a member function the compiler gets confused. Likewise if
    >>> I
    >>> try to use an enum. And I did qualify it where I used it outside the
    >>> class definition.
    >>>
    >>> Anybody want to try and explain /that/?

    >>
    >> Can you use C++ to show the problem instead of trying to explain
    >> in English? Many of us here understand C++ better than English,
    >> you know.

    >
    > #include <iostream>
    > //#define BROKEN
    > #ifndef BROKEN
    >
    > #define REDRO 3
    > #define REDRO2 REDRO
    >
    > #else
    >
    > #define REDRO ORDER
    > #define REDRO2 C<T>::ORDER
    >
    > #endif
    >
    > namespace sth{
    > template <typename T, unsigned N>
    > struct S
    > {
    > S():n(N){}
    > T n;
    > std::eek:stream& print(std::eek:stream& out) const
    > {
    > return out << "The value of n is:" << n << "\n";
    > }
    > };
    >
    > template<typename T>
    > class C {
    > public:
    > static const unsigned ORDER=3;
    >
    > const S<T, REDRO>& gimmie_s() const;
    >
    > protected:
    > S<T, REDRO> _s;
    >
    > };
    >
    > template <typename T>
    > const S<T, REDRO2>& C<T>::gimmie_s() const
    > {
    > return _s;
    > }
    > }
    >
    >
    > int main()
    > {
    > sth::C<float> c;
    > c.gimmie_s().print(std::cout);
    > }


    OK, when 'BROKEN' is defined, the program compiles with Comeau (online
    trial) but doesn't with some other compilers, I take it. MIPSpro gets
    it right too, BTW.

    So, ultimately your problem is with G++, and your beef with Mike was
    unfounded. Post to gnu.g++.help

    Victor
     
    Victor Bazarov, Oct 9, 2004
    #6
  7. Re: [OT, redir] Fun with error messages

    Victor Bazarov wrote:


    >
    > OK, when 'BROKEN' is defined, the program compiles with Comeau (online
    > trial) but doesn't with some other compilers, I take it. MIPSpro gets
    > it right too, BTW.
    >
    > So, ultimately your problem is with G++, and your beef with Mike was
    > unfounded. Post to gnu.g++.help
    >
    > Victor


    The last time that argument was given, I ended up sending mail the Bjarne
    Stroustrup telling him about the problem with his code.
    http://gcc.gnu.org/ml/gcc/2004-04/msg01268.html
    --
    "If our hypothesis is about anything and not about some one or more
    particular things, then our deductions constitute mathematics. Thus
    mathematics may be defined as the subject in which we never know what we
    are talking about, nor whether what we are saying is true." - Bertrand
    Russell
     
    Steven T. Hatton, Oct 9, 2004
    #7
  8. Re: [OT, redir] Fun with error messages

    "Steven T. Hatton" <> wrote...
    > Victor Bazarov wrote:
    >
    >
    >>
    >> OK, when 'BROKEN' is defined, the program compiles with Comeau (online
    >> trial) but doesn't with some other compilers, I take it. MIPSpro gets
    >> it right too, BTW.
    >>
    >> So, ultimately your problem is with G++, and your beef with Mike was
    >> unfounded. Post to gnu.g++.help
    >>
    >> Victor

    >
    > The last time that argument was given, I ended up sending mail the Bjarne
    > Stroustrup telling him about the problem with his code.


    What kind of "argument" are you looking for? The code is supposed to
    compile. And it does with at least two compilers I've tried. What else?
    Was that code from a book or something? What? If you want to get to
    the bottom of it, you will have to give more information. If you want
    to play games, count me out.

    V
     
    Victor Bazarov, Oct 11, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    65
    Views:
    1,825
    Mabden
    May 18, 2004
  2. dolphin
    Replies:
    4
    Views:
    343
    Jorgen Grahn
    Aug 25, 2007
  3. er
    Replies:
    2
    Views:
    543
  4. smarty
    Replies:
    4
    Views:
    197
    Steven Cheng[MSFT]
    May 22, 2006
  5. optimistx

    f = long.chain.of.identifiers.fun error?

    optimistx, Sep 30, 2009, in forum: Javascript
    Replies:
    21
    Views:
    208
Loading...

Share This Page