Look at this snippet:
int a;
extern int b;
auto b = a;
Is it well-formed? Clang successfully compiles it, but GCC and MSVC don't.
(This issue has come up when I answered How to declare and define a static member with deduced type?)
Clang, GCC, MSVC. (This answer previous stated that all 3 compilers would refuse to build it, but that was incorrect.)
dcl.spec.auto does not address the compatibility of multiple declarations of the same variable when mixing the auto
type specifier with other type specifiers. However, it addresses it for function return types:
auto f();
auto f() { return 42; } // return type is int
auto f(); // OK
int f(); // error, cannot be overloaded with auto f()
decltype(auto) f(); // error, auto and decltype(auto) don't match
So my intuition is that this is an oversight in the standard and the behavior is currently unspecified, but if/when it gets specified, there would be precedent to make it illegal. (On the other hand, variables can't be overloaded, so who knows.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With