[llvm-bugs] [Bug 50344] New: clang 12.0.0 ignores copy constructor and fails to compile seemingly correct code

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 14 10:21:36 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50344

            Bug ID: 50344
           Summary: clang 12.0.0 ignores copy constructor and fails to
                    compile seemingly correct code
           Product: new-bugs
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: f.kazmin at corp.mail.ru
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Created attachment 24857
  --> https://bugs.llvm.org/attachment.cgi?id=24857&action=edit
code in question

Hello,
I have got an issue on move/copy ctors with clang 12.0.0 compliling my code


Version:

[root at trgbuild build]# clang++ -v
clang version 12.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-last/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64


Code:

struct test_t {
    test_t(test_t&&) = delete;
    test_t(const test_t&) {};
    test_t() {};
};

test_t failing(void) {
    test_t tmp;
    return tmp;
}

int main(void) {
    return 0;
}


Observed behaviour:

[root at trgbuild build]# clang++ movector.cpp 
movector.cpp:9:12: error: call to deleted constructor of 'test_t'
    return tmp;
           ^~~
movector.cpp:2:5: note: 'test_t' has been explicitly marked deleted here
    test_t(test_t&&) = delete;
    ^
1 error generated.


Expected (by me) behaviour:
Compiles, provided copy constructor is used to return a value from function


Reasoning:

C++17 6.3.2/2:
> [Note: A return statement can involve an invocation of a constructor to perform a 
> copy or move of the operand if it is not a prvalue or if its type differs from the
> return type of the function.
So, compliler can use a copy constructor on return statement

https://en.cppreference.com/w/cpp/language/move_constructor:
> If only the copy constructor is provided, all argument categories select it
> (as long as it takes a reference to const, since rvalues can bind to const
> references), which makes copying the fallback for moving, when moving is
> unavailable.
So, it should use copy ctor having move ctor deleted


Is it a bug or I simply misunderstand something?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210514/39879b99/attachment.html>


More information about the llvm-bugs mailing list