]> granicus.if.org Git - clang/commitdiff
When the out-of-line definition differs from the declaration in the return type,
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 5 Feb 2011 05:54:49 +0000 (05:54 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 5 Feb 2011 05:54:49 +0000 (05:54 +0000)
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
lib/Sema/SemaDecl.cpp
test/SemaCXX/nested-name-spec.cpp

index df4c39e4ce78a9d749e429ea0e937b86860f5186..4c5db088022b2c2266790d5e2fab1d6585b4dddf 100644 (file)
@@ -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<
index 9db6814466626217859829fa67031700e6671c7a..aed950c8fccda95ad93dd5323ce1f23f56209403 100644 (file)
@@ -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;
       }
index 8d33f819af0ecfc83ed11958f5dcc7723771b4d7..1eb7014743cb1a3e2f250e34256d49caa3ba841b 100644 (file)
@@ -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}}
+}