public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/3136: Misleading error message / Bug?
@ 2001-06-14 18:55 rodrigc
0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-06-14 18:55 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, philipp.bachmann, rodrigc
Synopsis: Misleading error message / Bug?
State-Changed-From-To: open->feedback
State-Changed-By: rodrigc
State-Changed-When: Thu Jun 14 18:55:24 2001
State-Changed-Why:
Your test case is empty and only contains one line
with a comment.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3136&database=gcc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c++/3136: Misleading error message / Bug?
@ 2001-06-15 16:35 rodrigc
0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-06-15 16:35 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, philipp.bachmann, rodrigc
Synopsis: Misleading error message / Bug?
State-Changed-From-To: open->closed
State-Changed-By: rodrigc
State-Changed-When: Fri Jun 15 16:35:57 2001
State-Changed-Why:
gcc is not in error. There is a bug in your code.
The error message may be misleading though.
On line 74, of your test case:
return self.getMe();
The compiler creates a temporary variable
to store the result of getMe(), since self
is not a const reference.
What is happening is that on line 74:
return self.getMe();
When you return this temporary value, you are passing
it to a copy constructor which takes derived_t&
(without a const) as value. This is not allowed in C++.
Your options are to make self a const parameter to the
whatHappensHere() function.
This is similar to a bug report described here:
http://gcc.gnu.org/ml/gcc/2001-06/msg00765.html
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3136&database=gcc
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c++/3136: Misleading error message / Bug?
@ 2001-06-15 16:20 rodrigc
0 siblings, 0 replies; 4+ messages in thread
From: rodrigc @ 2001-06-15 16:20 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, philipp.bachmann, rodrigc
Synopsis: Misleading error message / Bug?
State-Changed-From-To: feedback->open
State-Changed-By: rodrigc
State-Changed-When: Fri Jun 15 16:20:20 2001
State-Changed-Why:
Received test case.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3136&database=gcc
^ permalink raw reply [flat|nested] 4+ messages in thread
* c++/3136: Misleading error message / Bug?
@ 2001-06-12 6:16 philipp.bachmann
0 siblings, 0 replies; 4+ messages in thread
From: philipp.bachmann @ 2001-06-12 6:16 UTC (permalink / raw)
To: gcc-gnats
>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;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-06-15 16:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-14 18:55 c++/3136: Misleading error message / Bug? rodrigc
-- strict thread matches above, loose matches on Subject: below --
2001-06-15 16:35 rodrigc
2001-06-15 16:20 rodrigc
2001-06-12 6:16 philipp.bachmann
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).