[llvm-bugs] [Bug 27949] New: implicit conversions and const rvalues

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 31 11:02:59 PDT 2016


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

            Bug ID: 27949
           Summary: implicit conversions and const rvalues
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eniebler at boost.org
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

GCC accepts the code below. Clang rejects it in C++11 mode and higher, but
accepts it in C++98 mode. Who is right?

struct ovrMatrix4f {
};

class Matrix4 {
public:
  operator const ovrMatrix4f () const {
    ovrMatrix4f result;
    return result;
  }
};

void ok() {
  Matrix4 from;
  ovrMatrix4f to = from; // that one is fine
}

void bad() {
  Matrix4 from;
  ovrMatrix4f to;
  to = from; // compilation fails here
}

Clang says:

test.cpp:20:8: error: no viable conversion from 'Matrix4' to 'ovrMatrix4f'
  to = from; // compilation fails here
       ^~~~
test.cpp:1:8: note: candidate constructor (the implicit copy constructor) not
viable: no known conversion from 'Matrix4' to
      'const ovrMatrix4f &' for 1st argument
struct ovrMatrix4f {
       ^
test.cpp:1:8: note: candidate constructor (the implicit move constructor) not
viable: no known conversion from 'Matrix4' to
      'ovrMatrix4f &&' for 1st argument
struct ovrMatrix4f {
       ^
test.cpp:6:3: note: candidate function
  operator const ovrMatrix4f () const {
  ^
test.cpp:1:8: note: passing argument to parameter here
struct ovrMatrix4f {
       ^

-- 
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/20160531/bd63d1f2/attachment-0001.html>


More information about the llvm-bugs mailing list