I was working on a code recently and I stumbled on something unusual in GCC and Clang. Using brace-init triggers a compilation error in gcc, while a direct initialization such as &b = a
works. The code below is a very simple example of that behaviour I encountered and I was wondering why GCC doesn't compile the code, since none of shared_ptr takes an initializer_list and a
is a lvalue
#include <iostream>
#include <memory>
int main( )
{
std::shared_ptr<int> a { nullptr }, &b { a };
a = std::make_shared<int> ( 1e3 );
std::cout << ( b ? *b : 0 ) << std::endl;
return 0;
}
Clang 3.4 compiles this but GCC 4.8 doesn't.