Skip to content

Commit 3aba9fd

Browse files
committed
[SemaCXX] Param diagnostic matches overload logic
Summary: 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. Reviewers: rsmith Reviewed By: rsmith Subscribers: cpplearner, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D57032 llvm-svn: 352831
1 parent 473e342 commit 3aba9fd

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5087,7 +5087,7 @@ static bool hasSimilarParameters(ASTContext &Context,
50875087
QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
50885088

50895089
// The parameter types are identical
5090-
if (Context.hasSameType(DefParamTy, DeclParamTy))
5090+
if (Context.hasSameUnqualifiedType(DefParamTy, DeclParamTy))
50915091
continue;
50925092

50935093
QualType DeclParamBaseTy = getCoreType(DeclParamTy);

clang/test/SemaCXX/function-redecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ bool Foo::isGood() { // expected-error {{out-of-line definition of 'isGood' does
125125
}
126126
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'?}}
127127
}
128+
129+
struct CVQualFun {
130+
void func(int a, int &b); // expected-note {{type of 2nd parameter of member declaration does not match definition ('int &' vs 'int')}}
131+
};
132+
133+
void CVQualFun::func(const int a, int b) {} // expected-error {{out-of-line definition of 'func' does not match any declaration in 'CVQualFun'}}

0 commit comments

Comments
 (0)