modocache created this revision.
modocache added a reviewer: rsmith.
Given the following test program:
class C {
public:
int A(int a, int& b);
};
int C::A(const int a, int b) {
return a * b;
}
Clang would produce an error message that correctly diagnosed the
redeclaration of `C::A` to not match the original declaration (the
parameters to the two declarations do not match -- the original takes an
`int &` as its 2nd parameter, but the redeclaration takes an `int`). However,
it also produced a note diagnostic that inaccurately pointed to the
first parameter, claiming that `const int` in the redeclaration did not
match the unqualified `int` in the original. The diagnostic is
misleading because it has nothing to do with why the program does not
compile.
The logic for checking for a function overload, in
`Sema::FunctionParamTypesAreEqual`, discards cv-qualifiers before
checking whether the types are equal. Do the same when producing the
overload diagnostic.
Repository:
rC Clang
https://reviews.llvm.org/D57032
Files:
lib/Sema/SemaDecl.cpp
test/SemaCXX/function-redecl.cpp
Index: test/SemaCXX/function-redecl.cpp
===================================================================
--- test/SemaCXX/function-redecl.cpp
+++ test/SemaCXX/function-redecl.cpp
@@ -125,3 +125,9 @@
}
void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil'
does not match any declaration in namespace 'redecl_typo::Foo'; did you mean
'BeEvil'?}}
}
+
+struct CVQualFun {
+ void func(int a, int &b); // expected-note {{type of 2nd parameter of member
declaration does not match definition ('int &' vs 'int')}}
+};
+
+void CVQualFun::func(const int a, int b) {} // expected-error {{out-of-line
definition of 'func' does not match any declaration in 'CVQualFun'}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5089,7 +5089,8 @@
QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
// The parameter types are identical
- if (Context.hasSameType(DefParamTy, DeclParamTy))
+ if (Context.hasSameType(DefParamTy.getUnqualifiedType(),
+ DeclParamTy.getUnqualifiedType()))
continue;
QualType DeclParamBaseTy = getCoreType(DeclParamTy);
Index: test/SemaCXX/function-redecl.cpp
===================================================================
--- test/SemaCXX/function-redecl.cpp
+++ test/SemaCXX/function-redecl.cpp
@@ -125,3 +125,9 @@
}
void Foo::beEvil() {} // expected-error {{out-of-line definition of 'beEvil' does not match any declaration in namespace 'redecl_typo::Foo'; did you mean 'BeEvil'?}}
}
+
+struct CVQualFun {
+ void func(int a, int &b); // expected-note {{type of 2nd parameter of member declaration does not match definition ('int &' vs 'int')}}
+};
+
+void CVQualFun::func(const int a, int b) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'CVQualFun'}}
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -5089,7 +5089,8 @@
QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
// The parameter types are identical
- if (Context.hasSameType(DefParamTy, DeclParamTy))
+ if (Context.hasSameType(DefParamTy.getUnqualifiedType(),
+ DeclParamTy.getUnqualifiedType()))
continue;
QualType DeclParamBaseTy = getCoreType(DeclParamTy);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits