https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70576
Bug ID: 70576
Summary: G++ compiles and links invalid code when shadowing
global function in function scope
Product: gcc
Version: 5.3.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jaak at ristioja dot ee
Target Milestone: ---
int foo() { return 2; }
int main() {
int& foo();
foo() = 42; // Segfault
}
First detected here:
https://stackoverflow.com/questions/36477542/what-does-int-foo-mean-in-c
Compiles with GCC 4.7.4, 4.8.5, 4.9.3 and 5.3.0 without any warnings with -Wall
-Wextra -Wshadow.
Clang errors with:
test.cpp:3:8: error: functions that differ only in their return type cannot be
overloaded
int& foo();
~~~~ ^
test.cpp:1:5: note: previous definition is here