public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/21631] New: Diagnostic for misdefined copy constructor is not particularly clear
@ 2005-05-17 19:56 pkoning at equallogic dot com
  2005-05-17 20:00 ` [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor) pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: pkoning at equallogic dot com @ 2005-05-17 19:56 UTC (permalink / raw)
  To: gcc-bugs

If I define a copy constructor as T(T&) rather than the correct T(const T&),
I'll end up with messages of the form:

| > keyed_obj.hh:159: error: no matching function for call to
'CxnIndex::CxnIndex(CxnIndex)'
| > Indeces.hh:150: note: candidates are: CxnIndex::CxnIndex(CxnIndex&)

which is baffling to most users because usually an argument of type T& is
acceptable for a call with a type T argument.  It doesn't help that there isn't
a call in the source code -- the compiler generated a copy constructor
reference, for reasons that may not be obvious from reading the source.

It would be helpful if the compiler could guide the user to the fix, perhaps by
doing one or both of the following:

a. Warn on the declaration of T(T&) with a message along the lines of "that
looks like a copy constructor, but it really should be T(const T&)"

b. In the message I quoted above, mention that a T(const T&) is needed and was
not supplied.

-- 
           Summary: Diagnostic for misdefined copy constructor is not
                    particularly clear
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pkoning at equallogic dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-netbsd
  GCC host triplet: i386-netbsd
GCC target triplet: mipsel-netbsdelf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor)
  2005-05-17 19:56 [Bug c++/21631] New: Diagnostic for misdefined copy constructor is not particularly clear pkoning at equallogic dot com
@ 2005-05-17 20:00 ` pinskia at gcc dot gnu dot org
  2005-05-17 20:17 ` pinskia at gcc dot gnu dot org
  2005-09-17  3:58 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-17 20:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-17 20:00 -------
Confirmed, simple example:
struct f
{
  f(f&);
};
int g(void)
{
  f a = f();
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-17 20:00:40
               date|                            |
            Summary|Diagnostic for misdefined   |diagnostic for a non
                   |copy constructor is not     |constant reference when
                   |particularly clear          |passed a non lvalue (copy
                   |                            |constructor)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor)
  2005-05-17 19:56 [Bug c++/21631] New: Diagnostic for misdefined copy constructor is not particularly clear pkoning at equallogic dot com
  2005-05-17 20:00 ` [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor) pinskia at gcc dot gnu dot org
@ 2005-05-17 20:17 ` pinskia at gcc dot gnu dot org
  2005-09-17  3:58 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-17 20:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-17 20:17 -------
Note T(T&) is still a copy constructor, just not one which takes a constant reference.
Also note:
it really bolls down to this testcase:
int  f(int&);
int f();
int g(void)
{
  return f(1);
}

If we get rid of the second f function, we get a good warning.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor)
  2005-05-17 19:56 [Bug c++/21631] New: Diagnostic for misdefined copy constructor is not particularly clear pkoning at equallogic dot com
  2005-05-17 20:00 ` [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor) pinskia at gcc dot gnu dot org
  2005-05-17 20:17 ` pinskia at gcc dot gnu dot org
@ 2005-09-17  3:58 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-17  3:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
   Last reconfirmed|2005-05-17 20:00:40         |2005-09-17 03:57:49
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor)
       [not found] <bug-21631-4@http.gcc.gnu.org/bugzilla/>
  2014-05-14 16:48 ` jason at gcc dot gnu.org
@ 2014-05-14 18:31 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-14 18:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
   Target Milestone|---                         |4.10.0

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed on trunk.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor)
       [not found] <bug-21631-4@http.gcc.gnu.org/bugzilla/>
@ 2014-05-14 16:48 ` jason at gcc dot gnu.org
  2014-05-14 18:31 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-14 16:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21631

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Wed May 14 16:48:07 2014
New Revision: 210436

URL: http://gcc.gnu.org/viewcvs?rev=210436&root=gcc&view=rev
Log:
    PR c++/20332
    PR c++/21631
    * call.c (reference_binding): Treat lvalue/rvalue mismatch and
    dropped cv-quals as a bad conversion.
    (convert_like_real) [ck_ref_bind]: Explain them.
    (compare_ics): Check badness before stripping reference
    bindings.  Handle comparing bad reference bindings.
    * typeck.c (comp_cv_qualification): Add overload that just takes
    integers.
    * cp-tree.h: Declare it.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/diag2.C
    trunk/gcc/testsuite/g++.dg/diagnostic/ref1.C
    trunk/gcc/testsuite/g++.dg/diagnostic/ref2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/g++.dg/conversion/op4.C
    trunk/gcc/testsuite/g++.dg/cpp0x/overloadn.C
    trunk/gcc/testsuite/g++.dg/expr/cond9.C
    trunk/gcc/testsuite/g++.dg/init/synth2.C
    trunk/gcc/testsuite/g++.dg/lookup/two-stage4.C
    trunk/gcc/testsuite/g++.dg/overload/arg3.C
    trunk/gcc/testsuite/g++.dg/overload/conv-op1.C
    trunk/gcc/testsuite/g++.dg/overload/copy1.C
    trunk/gcc/testsuite/g++.dg/overload/volatile1.C
    trunk/gcc/testsuite/g++.dg/rtti/dyncast6.C
    trunk/gcc/testsuite/g++.dg/template/copy1.C
    trunk/gcc/testsuite/g++.old-deja/g++.benjamin/15800-1.C
    trunk/gcc/testsuite/g++.old-deja/g++.brendan/cvt3.C
    trunk/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C
    trunk/gcc/testsuite/g++.old-deja/g++.eh/ctor1.C
    trunk/gcc/testsuite/g++.old-deja/g++.jason/temporary2.C
    trunk/gcc/testsuite/g++.old-deja/g++.law/cvt20.C
    trunk/gcc/testsuite/g++.old-deja/g++.law/enum4.C
    trunk/gcc/testsuite/g++.old-deja/g++.law/init8.C
    trunk/gcc/testsuite/g++.old-deja/g++.law/operators9.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/net8.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/p1989.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/p2431.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/p438.C
    trunk/gcc/testsuite/g++.old-deja/g++.mike/p701.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/crash24.C
    trunk/gcc/testsuite/g++.old-deja/g++.other/volatile1.C
    trunk/gcc/testsuite/g++.old-deja/g++.pt/auto_ptr.C
    trunk/gcc/testsuite/g++.old-deja/g++.pt/t05.C
    trunk/libstdc++-v3/testsuite/20_util/forward/1_neg.cc


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-14 18:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-17 19:56 [Bug c++/21631] New: Diagnostic for misdefined copy constructor is not particularly clear pkoning at equallogic dot com
2005-05-17 20:00 ` [Bug c++/21631] diagnostic for a non constant reference when passed a non lvalue (copy constructor) pinskia at gcc dot gnu dot org
2005-05-17 20:17 ` pinskia at gcc dot gnu dot org
2005-09-17  3:58 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21631-4@http.gcc.gnu.org/bugzilla/>
2014-05-14 16:48 ` jason at gcc dot gnu.org
2014-05-14 18:31 ` jason at gcc dot gnu.org

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).