Date: Wed, 19 Nov 2025 14:44:20 +0800
On Wed, 19 Nov 2025 at 10:45, Brian Bi <bbi5291_at_[hidden]> wrote:
>> Somebody encountered a strange case, which made me interested. It can
>> be simplified to the following code:
>>
>> #include <iostream>
>>
>> using namespace std;
>>
>> struct B {
>> B() { cout << this << endl; }
>> //B(const B&) = delete;
>> //B(const B&) {}
>> };
>>
>> B get()
>> {
>> return B{};
>> }
>>
>> int main()
>> {
>> B b = get();
>> cout << &b << endl;
>> }
>>
>> https://godbolt.org/z/q3xx3xdcn
>>
>> The code will output two different addresses on Clang and GCC.
>> However, uncommenting any of the copy-constructor would behave
>> differently.
Big THANKS!
If you happen to read Chinese, the full context is here:
https://www.zhihu.com/question/1974139282634594215/answer/1974425143318169069
>> Somebody encountered a strange case, which made me interested. It can
>> be simplified to the following code:
>>
>> #include <iostream>
>>
>> using namespace std;
>>
>> struct B {
>> B() { cout << this << endl; }
>> //B(const B&) = delete;
>> //B(const B&) {}
>> };
>>
>> B get()
>> {
>> return B{};
>> }
>>
>> int main()
>> {
>> B b = get();
>> cout << &b << endl;
>> }
>>
>> https://godbolt.org/z/q3xx3xdcn
>>
>> The code will output two different addresses on Clang and GCC.
>> However, uncommenting any of the copy-constructor would behave
>> differently.
Big THANKS!
If you happen to read Chinese, the full context is here:
https://www.zhihu.com/question/1974139282634594215/answer/1974425143318169069
Received on 2025-11-19 06:44:37
