[llvm-bugs] [Bug 42317] New: explicit refuses the call to other implicit constructors

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 19 02:39:25 PDT 2019


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

            Bug ID: 42317
           Summary: explicit refuses the call to other implicit
                    constructors
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zhonghao at pku.org.cn
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

My clang is 9.0.0, and the code is:

struct A;

struct B
{
 B(A const &);
 B(B const &);
};

struct A
{
 A(B) {}
};

B f(A const &a) { 
  B r(a);
  return r; 
}

clang accepts the code, but after I modify it to:

struct A;

struct B
{
 B(A const &);
 explicit B(B const &);
};

struct A
{
 A(B) {}
};

B f(A const &a) { 
  B r(a);
  return r; 
}

clang rejects it:

<source>:16:10: error: no matching constructor for initialization of 'B'

  return r; 

         ^

<source>:5:2: note: candidate constructor not viable: no known conversion from
'B' to 'const A &' for 1st argument

 B(A const &);

 ^

<source>:11:5: note: passing argument to parameter here

 A(B) {}

    ^

1 error generated.

Compiler returned: 1

It is strange to refuse the call to B(A const &), after I modify to the other
constructor to explicit. The buggy location is also strange, since return r
does not call any constructors. 

BTW, gcc accepts both code samples.

-- 
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/20190619/677de868/attachment.html>


More information about the llvm-bugs mailing list