This answer claims that a const auto pointer behaves the same as a const 'regular' (i.e., non-auto) pointer, which is what I would expect.
However, the following code compiles and outputs 100:
int n{ 99 };
const auto nPtr = &n;
++(*nPtr);
std::cout << n << '\n';
To dig a little deeper, I checked the types of all 4 kinds of pointers and this is the result I got:
Code
int n{ 99 };
int* intPtr = &n;
const int* intConstPtr = &n;
auto autoPtr = &n;
const auto autoConstPtr = &n;
std::cout << "intPtr: " << typeid(intPtr).name() << '\n';
std::cout << "intConstPtr: " << typeid(intConstPtr).name() << '\n';
std::cout << "autoPtr: " << typeid(autoPtr).name() << '\n';
std::cout << "autoConstPtr: " << typeid(autoConstPtr).name() << '\n';
Output
intPtr: int * __ptr64
intConstPtr: int const * __ptr64
autoPtr: int * __ptr64
autoConstPtr: int * __ptr64
So the compiler seems to be completely ignoring the const keyword with the auto pointer. Does anyone know why this is?