[LLVMbugs] [Bug 11528] New: -Wbind-to-temporary warns if field in class has a type with a non-const copy constructor.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Dec 9 15:21:03 PST 2011


             Bug #: 11528
           Summary: -Wbind-to-temporary warns if field in class has a type
                    with a non-const copy constructor.
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ajwong at chromium.org
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

struct A {

 A(A& other) {}

class B {
  A field_;

void Func(const B& t) {}

int main(void) {
  return 0;

This triggers -Wbind-to-temporary-copy:

$ ./third_party/llvm-build/Release+Asserts/bin/clang++ -c /tmp/bad3.cc
/tmp/bad3.cc:15:8: warning: no viable constructor copying parameter of type
'B'; C++98 requires a copy constructor when binding a reference to a temporary
/tmp/bad3.cc:8:7: note: candidate constructor (the implicit copy constructor)
not viable: no known conversion from 'B' to 'B &' for 1st argument;
class B {

If A's copy constructor is defined using a const-reference as in A(const A&
other) {}, the warning does not fire.

I *think* the warning should still not fire even if A's copy constructor is
non-const because B's implicit copy constructor should still be public.  If the
warning is actually accurate, then we have a separate problem where the
diagnostic is very confusing since it talks about B converting to B&.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list