c++/3136: Misleading error message / Bug?
philipp.bachmann@obtree.com
philipp.bachmann@obtree.com
Tue Jun 12 06:16:00 GMT 2001
>Number: 3136
>Category: c++
>Synopsis: Misleading error message / Bug?
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 12 06:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Philipp Bachmann
>Release: g++ 2.95.3
>Organization:
>Environment:
Sun Solaris 7 SPARC
>Description:
When "CONST" in the sample code provided is defined
to be empty, then the following error message is
printed by g++:
copyConstr.c++: In function 'class derived_t whatHappensHere(base_t)':
copyConstr.c++:74: conversion from 'base_t' to non-scalar type 'derived_t' requested.
If either
(1) "CONST" is defined as "const" or
(2) line 74 is commented out and line 73 is commented in,
then the error message completely
vanishes.
I can understand the necessity for "const" (i.e. Fix (1))
- but that Fix (2) solves the problem I'm surprised about.
So my interpretation is twofold: The error message is misleading
and g++ has a small bug.
>How-To-Repeat:
via Email
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="copyConstr.c++.txt"
Content-Disposition: inline; filename="copyConstr.c++.txt"
/* Very simple program to demonstrate misleading error message
of GNU g++ 2.95.3. */
/* $Log: copyconstr.c++,v $
* Revision 1.2 2001/06/12 13:58:07 bachlipp
* Introduced "base_t::getMe() const".
*
* Revision 1.1 2001/06/12 13:32:39 bachlipp
* Initial revision
* */
static const char rcsid[]="@@(#)$Id: copyconstr.c++,v 1.2 2001/06/12 13:58:07 bachlipp Exp $";
#include<iostream>
#define CONST
// #define CONST const
class base_t {
public :
base_t(void);
base_t(const base_t &);
virtual ~base_t(void);
virtual base_t getMe(void) const;
};
class derived_t : public base_t {
public:
derived_t(void);
derived_t(const derived_t &);
derived_t(CONST base_t &);
~derived_t(void);
};
derived_t whatHappensHere(base_t);
base_t::base_t(void) {
std::cerr<<"\"base_t::Constructor\" called."<<std::endl;
}
base_t::base_t(const base_t &org) {
std::cerr<<"\"base_t::Copyconstructor\" called."<<std::endl;
}
base_t::~base_t(void) {
std::cerr<<"\"base_t::Destructor\" called."<<std::endl;
}
base_t base_t::getMe(void) const {
std::cerr<<"\"base_t::getMe\" called."<<std::endl;
return *this;
}
derived_t::derived_t(void) : base_t() {
std::cerr<<"\"derived_t::Constructor\" called."<<std::endl;
}
derived_t::derived_t(const derived_t &org) : base_t(org) {
std::cerr<<"\"derived_t::Copyconstructor\" called."<<std::endl;
}
derived_t::derived_t(CONST base_t &org) : base_t(org) {
std::cerr<<"\"derived_t::PerverseCopyconstructor\" called."<<std::endl;
}
derived_t::~derived_t(void) {
std::cerr<<"\"derived_t::Destructor\" called."<<std::endl;
}
derived_t whatHappensHere(base_t self) {
std::cerr<<"\"whatHappensHere()\" started."<<std::endl;
// return self;
return self.getMe();
}
int main() {
derived_t der;
whatHappensHere(der);
std::cerr<<"\"main()\": done."<<std::endl;
return 0;
}
More information about the Gcc-bugs
mailing list