By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Fun with error messages

P: n/a
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>::operator[](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>::operator[](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>::operator[](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>::operator[](int&)
IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::operator[](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

Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote in message
news:zu********************@speakeasy.net...
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>::operator[](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>::operator[](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>::operator[](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>::operator[](int&)
IndexedReference<T, Matrix3<T>::ORDER>& Matrix3<T>::operator[](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
Jul 22 '05 #2

P: n/a
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*outsid e*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

Jul 22 '05 #3

P: n/a
"Steven T. Hatton" <su******@setidava.kushan.aa> 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
Jul 22 '05 #4

P: n/a
Victor Bazarov wrote:
"Steven T. Hatton" <su******@setidava.kushan.aa> 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::ostream& print(std::ostream& 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

Jul 22 '05 #5

P: n/a
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote...
Victor Bazarov wrote:
"Steven T. Hatton" <su******@setidava.kushan.aa> 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::ostream& print(std::ostream& 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
Jul 22 '05 #6

P: n/a
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

Jul 22 '05 #7

P: n/a
"Steven T. Hatton" <su******@setidava.kushan.aa> 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
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.