https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69855
Bug ID: 69855 Summary: Missing diagnostic for overload that only differs by return type Product: gcc Version: 6.0 Status: UNCONFIRMED Keywords: accepts-invalid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- The following code intended to create a local mutex but instead declared a function: #include <mutex> std::mutex& get(); void f() { std::lock_guard<std::mutex>(get()); // oops! mutex not locked } But this should be invalid, because get() is already declared in the enclosing scope and the return type is not the same. By failing to diagnose this error we allow the code above to compile and run without locking the mutex. Reduced: struct mutex { }; mutex& get(); struct guard { guard(mutex&) { } }; void f() { guard(get()); } Clang says: ww.cc:12:9: error: functions that differ only in their return type cannot be overloaded guard(get()); ^ ww.cc:4:8: note: previous declaration is here mutex& get(); ~~~~~~ ^ 1 error generated. EDG says: "ww.cc", line 12: error: declaration is incompatible with previous "get" (declared at line 4) guard(get()); ^ 1 error detected in the compilation of "ww.cc".