Is it allowed to overload function with parameters that differs by top-level const-ness?

c++

Solution

The compiler considers these two declarations

void foo(int);
void foo(const int);

as declarations of the same function.

According to the C++ Standard

— Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent. That is, the const and volatile type-specifiers for each parameter type are ignored when determining which function is being declared, defined, or called

Problem

I was confused that the compiler allowed overloading with only top-level const-ness when I test below code: ``` void foo(int); void foo(const int); int main() { return 0; } ``` And here is the compilation result: ``` g++ -O0 testoverloading3.cpp -lm -o testoverloading3 -g -Wall -lpthread -std=c++11 Compilation finished at Wed Jul 9 15:45:35 ``` This contradicts my understanding that top-level const-ness only shall not be overloaded. Was I missing some setting here?

Original source