diff options
author | Richard Trieu <rtrieu@google.com> | 2011-12-13 23:19:45 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2011-12-13 23:19:45 +0000 |
commit | a6dc7eff27a8c59bee42809270971931b811dd44 (patch) | |
tree | c3d74da244ec16825dd5e2f21f278443cac8b0a7 | |
parent | 7209646add692c50503435bcffb13187a3349552 (diff) |
Make the diagnostic message more consistant. Update the type comparison to
handle non-pointer types. This is for the extra info printed when function
types are compared.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146525 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 27 | ||||
-rw-r--r-- | test/SemaCXX/addr-of-overloaded-function.cpp | 2 |
3 files changed, 19 insertions, 14 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 941944c8a4..84be9a269c 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1023,7 +1023,7 @@ def err_init_conversion_failed : Error< "%select{rvalue|lvalue}2 of type %3" "%select{|: different classes (%5 vs %6)" "|: different number of parameters (%5 vs %6)" - "|: type mismatch in %ordinal5 parameter (%6 vs %7)" + "|: type mismatch at %ordinal5 parameter (%6 vs %7)" "|: different return type (%5 vs %6)" "|: different qualifiers (" "%select{none|const|restrict|const and restrict|volatile|const and volatile|" @@ -1855,7 +1855,7 @@ def note_ovl_candidate : Note<"candidate " "is an inherited constructor}0%1" "%select{| has different class (expected %3 but has %4)" "| has different number of parameters (expected %3 but has %4)" - "| has type mismatch in %ordinal3 parameter (expected %4 but has %5)" + "| has type mismatch at %ordinal3 parameter (expected %4 but has %5)" "| has different return type (%3 expected but has %4)" "| has different qualifiers (expected " "%select{none|const|restrict|const and restrict|volatile|const and volatile" diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 86181040ce..7ddb151e8a 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -2177,6 +2177,12 @@ enum { /// parameter types, and different return types. void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, QualType FromType, QualType ToType) { + // If either type is not valid, include no extra info. + if (FromType.isNull() || ToType.isNull()) { + PDiag << ft_default; + return; + } + // Get the function type from the pointers. if (FromType->isMemberPointerType() && ToType->isMemberPointerType()) { const MemberPointerType *FromMember = FromType->getAs<MemberPointerType>(), @@ -2188,27 +2194,26 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, } FromType = FromMember->getPointeeType(); ToType = ToMember->getPointeeType(); - } else if (FromType->isPointerType() && ToType->isPointerType()) { + } + + if (FromType->isPointerType()) FromType = FromType->getPointeeType(); + if (ToType->isPointerType()) ToType = ToType->getPointeeType(); - } else { - PDiag << ft_default; - return; - } + // Remove references. FromType = FromType.getNonReferenceType(); ToType = ToType.getNonReferenceType(); - // If either type is not valid, of the types are the same, no extra info. - if (FromType.isNull() || ToType.isNull() || - Context.hasSameType(FromType, ToType)) { + // Don't print extra info for non-specialized template functions. + if (FromType->isInstantiationDependentType() && + !FromType->getAs<TemplateSpecializationType>()) { PDiag << ft_default; return; } - // Don't print extra info for non-specialized template functions. - if (FromType->isInstantiationDependentType() && - !FromType->getAs<TemplateSpecializationType>()) { + // No extra info for same types. + if (Context.hasSameType(FromType, ToType)) { PDiag << ft_default; return; } diff --git a/test/SemaCXX/addr-of-overloaded-function.cpp b/test/SemaCXX/addr-of-overloaded-function.cpp index af171ec701..f9cc11174c 100644 --- a/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/test/SemaCXX/addr-of-overloaded-function.cpp @@ -156,7 +156,7 @@ namespace test1 { } void parameter_mismatch() { - void (*ptr1)(double) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(double)' with an rvalue of type 'void (*)(int)': type mismatch in 1st parameter ('double' vs 'int')}} + void (*ptr1)(double) = &fun; // expected-error {{cannot initialize a variable of type 'void (*)(double)' with an rvalue of type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} void (*ptr2)(double); ptr2 = &fun; // expected-error {{assigning to 'void (*)(double)' from incompatible type 'void (*)(int)': type mismatch at 1st parameter ('double' vs 'int')}} } |