public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: philipp.bachmann@obtree.com
To: gcc-gnats@gcc.gnu.org
Subject: c++/3136: Misleading error message / Bug?
Date: Tue, 12 Jun 2001 06:16:00 -0000	[thread overview]
Message-ID: <20010612130926.18398.qmail@sourceware.cygnus.com> (raw)

>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;
}


             reply	other threads:[~2001-06-12  6:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-12  6:16 philipp.bachmann [this message]
2001-06-14 18:55 rodrigc
2001-06-15 16:20 rodrigc
2001-06-15 16:35 rodrigc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010612130926.18398.qmail@sourceware.cygnus.com \
    --to=philipp.bachmann@obtree.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).