[cfe-commits] r146525 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/SemaCXX/addr-of-overloaded-function.cpp
Richard Trieu
rtrieu at google.com
Tue Dec 13 15:19:46 PST 2011
Author: rtrieu
Date: Tue Dec 13 17:19:45 2011
New Revision: 146525
URL: http://llvm.org/viewvc/llvm-project?rev=146525&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146525&r1=146524&r2=146525&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 17:19:45 2011
@@ -1023,7 +1023,7 @@
"%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 @@
"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"
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=146525&r1=146524&r2=146525&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Dec 13 17:19:45 2011
@@ -2177,6 +2177,12 @@
/// 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 @@
}
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;
}
Modified: cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp?rev=146525&r1=146524&r2=146525&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/addr-of-overloaded-function.cpp Tue Dec 13 17:19:45 2011
@@ -156,7 +156,7 @@
}
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')}}
}
More information about the cfe-commits
mailing list