[cfe-dev] implicit conversions and const rvalues

Eric Niebler via cfe-dev cfe-dev at lists.llvm.org
Fri May 27 09:49:17 PDT 2016


GCC accepts the code below. Clang rejects it. 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 {
       ^


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160527/5a27371a/attachment.html>


More information about the cfe-dev mailing list