Created attachment 36506 [details] Test case Compiling following code produces incorrect error message: #include <cstdint> void foo(std::size_t &f) { f = 5; } struct A { uint32_t val; }; int main() { A a, *aptr = &a; foo(aptr->val); return 0; } g++ --std=c++11 foo.cpp gives error message: error: invalid initialization of non-const reference of type ‘std::size_t& {aka long unsigned int&}’ from an rvalue of type ‘std::size_t {aka long unsigned int}’ foo(aptr->val); ^ where type of that rvalue variable is uint32_t not std::size_t. I think I should add that system is 64bit so std::size_t has 64 bits.
The diagnostic is correct. Trying to pass uint32_t to a function taking size_t causes a conversion, creating a temporary (i.e. rvalue) size_t, but a non-const reference cannot bind to a temporary.
(In reply to other+gcc from comment #0) > where type of that rvalue variable is uint32_t not std::size_t. There is no rvalue of type uint32_t. The type of the **lvalue** is uint32_t. The rvalue is the temporary that gets created implicitly, which is of type size_t. FWIW clang doesn't mention rvalues, it just says there is no matching function for the call because ... prog.cc:4:6: note: candidate function not viable: no known conversion from 'std::uint32_t' (aka 'unsigned int') to 'std::size_t &' (aka 'unsigned long &') for 1st argument
Closing then.