This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/70576] New: G++ compiles and links invalid code when shadowing global function in function scope
- From: "jaak at ristioja dot ee" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 07 Apr 2016 13:50:00 +0000
- Subject: [Bug c++/70576] New: G++ compiles and links invalid code when shadowing global function in function scope
- Auto-submitted: auto-generated
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