From 1de34dd8a6932fbb316e35304bf468ddb4a0841b Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 5 Feb 2011 05:54:49 +0000 Subject: [PATCH] When the out-of-line definition differs from the declaration in the return type, say "out-of-line definition differ from the declaration in the return type" instead of the silly "functions that differ only in their return type cannot be overloaded". Addresses rdar://7980179. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124939 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ lib/Sema/SemaDecl.cpp | 6 +++++- test/SemaCXX/nested-name-spec.cpp | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index df4c39e4ce..4c5db08802 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2343,6 +2343,8 @@ def err_member_def_undefined_record : Error< "out-of-line definition of %0 from class %1 without definition">; def err_member_def_does_not_match : Error< "out-of-line definition of %0 does not match any declaration in %1">; +def err_member_def_does_not_match_ret_type : Error< + "out-of-line definition of %q0 differ from the declaration in the return type">; def err_nonstatic_member_out_of_line : Error< "non-static data member defined out-of-line">; def err_nonstatic_flexible_variable : Error< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 9db6814466..aed950c8fc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1201,7 +1201,11 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { && OldReturnType->isObjCObjectPointerType()) ResQT = Context.mergeObjCGCQualifiers(NewQType, OldQType); if (ResQT.isNull()) { - Diag(New->getLocation(), diag::err_ovl_diff_return_type); + if (New->isCXXClassMember() && New->isOutOfLine()) + Diag(New->getLocation(), + diag::err_member_def_does_not_match_ret_type) << New; + else + Diag(New->getLocation(), diag::err_ovl_diff_return_type); Diag(Old->getLocation(), PrevDiag) << Old << Old->getType(); return true; } diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 8d33f819af..1eb7014743 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -258,3 +258,8 @@ namespace PR8159 { int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}} }; } + +namespace rdar7980179 { + class A { void f0(); }; // expected-note {{previous}} + int A::f0() {} // expected-error {{out-of-line definition of 'rdar7980179::A::f0' differ from the declaration in the return type}} +} -- 2.40.0