Fun with error messages

  • Thread starter Steven T. Hatton
  • Start date
S

Steven T. Hatton

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
 
M

Mike Wahler

Steven T. Hatton said:
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 said:
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
 
S

Steven T. Hatton

Mike said:
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
 
V

Victor Bazarov

Steven T. Hatton said:
[...]
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
 
S

Steven T. Hatton

Victor said:
Steven T. Hatton said:
[...]
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
 
V

Victor Bazarov

Steven T. Hatton said:
Victor said:
Steven T. Hatton said:
[...]
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
 
S

Steven T. Hatton

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
 
V

Victor Bazarov

Steven T. Hatton said:
Victor Bazarov wrote:



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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top