http://llvm.org/bugs/show_bug.cgi?id=22426
Richard Smith <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |[email protected] Resolution|--- |INVALID --- Comment #2 from Richard Smith <[email protected]> --- (In reply to comment #0) > There should *never* be an error when using decltype(auto). That is true if the returned expression is a function call, but there are a few cases where decltype(auto) returns can fail[1]. This is one of them. decltype applied to the returned expression returns the declared type of the member, due to a special case for class member access. In this case, the declared type of the member is 'int &&', but the member access expression is an int lvalue, so the reference binding fails. You can get the result you expect here by a syntactic contortion: add another pair of parens around your returned expression: return (((decltype(p)&&)p).first); This causes decltype to ignore that it's in the 'class member access expression' special case. Note that this special case is in fact essential in other uses of decltype(auto): struct Q { int n; }; decltype(auto) f(Q q) { return q.n; } Without the special case that is causing you problems here, the above function would have return type 'int &' rather than 'int', which is obviously bad. [1] This can happen in two ways: 1) the computed type is *not* the type of the expression plus & or && for an lvalue or xvalue (this happens if we fall into [dcl.type.simple]/4.1) 2) the expression can't actually be used to initialize an object of its own type We're in case (1) here; for completeness, an example of case (2) would be: struct X { int n : 1; }; decltype(auto) f(X x) { return (x.n); } Here, decltype(auto) computes the type int&, which cannot bind to a bit-field. Here's another: unique_ptr<int> u; decltype(auto) f() { return u; } -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ LLVMbugs mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs
