[cfe-commits] PR7245: Make rvalue->reference copy errors into warnings. (issue1407042)

doug.gregor at gmail.com doug.gregor at gmail.com
Fri Jun 4 16:23:08 PDT 2010


Here's some example code that is well-formed C++98 (since the lack of a
suitable copy constructor kicks the first g() template out of the
overload set) but triggers an ambiguity in C++0x (where we don't look
for the copy constructor):

class X {
   X(X&);

public:
   X();
};

template<int> struct int_c { };

template<typename T> T f(const T&);

template<typename T>
int &g(int_c<sizeof(f(T()))> * = 0);

template<typename T> float &g();

void h() {
   float &fp = g<X>();
}

With the changes I've mentioned, please go ahead and commit.


http://codereview.appspot.com/1407042/diff/8001/9002
File include/clang/Basic/DiagnosticGroups.td (right):

http://codereview.appspot.com/1407042/diff/8001/9002#newcode76
include/clang/Basic/DiagnosticGroups.td:76: def RvalueCopyCtor :
DiagGroup<"rvalue-copy-ctor">;
I think that the name "rvalue-copy-ctor" for this warning group is
somewhat misleading; this is about binding a reference to a temporary. I
don't have any great ideas, but perhaps something like
"-Wbind-to-temporary-copy"?

http://codereview.appspot.com/1407042/diff/8001/9003
File include/clang/Basic/DiagnosticSemaKinds.td (right):

http://codereview.appspot.com/1407042/diff/8001/9003#newcode492
include/clang/Basic/DiagnosticSemaKinds.td:492: NoSFINAE,
InGroup<RvalueCopyCtor>;
how about "when binding a reference to a temporary"

http://codereview.appspot.com/1407042/diff/8001/9003#newcode756
include/clang/Basic/DiagnosticSemaKinds.td:756: "constructor when
binding an rvalue to a reference">,
same comment: "when binding a reference to a temporary" ?

http://codereview.appspot.com/1407042/diff/8001/9005
File lib/Sema/SemaInit.cpp (right):

http://codereview.appspot.com/1407042/diff/8001/9005#newcode3327
lib/Sema/SemaInit.cpp:3327: S.Diag(Loc, IsExtraneousCopy
Use "IsExtraneousCopy && !S.isSFINAEContext()" to keep the error within
SFINAE context.

http://codereview.appspot.com/1407042/diff/8001/9005#newcode3334
lib/Sema/SemaInit.cpp:3334: return S.ExprError();
You're going to need to make this:

   if (!IsExtraneousCopy || S.isSFINAEContext())
     return S.ExprError();
   return move(CurInit);

As it stands, you've downgraded the error to a warning, but the
initialization code is still returning an error.

http://codereview.appspot.com/1407042/show



More information about the cfe-commits mailing list