[cfe-commits] r61058 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/SemaCXX/nested-name-spec.cpp
Douglas Gregor
dgregor at apple.com
Tue Dec 16 08:16:54 PST 2008
Hi Sebastian,
On Dec 16, 2008, at 5:06 PM, Sebastian Redl wrote:
> Douglas Gregor wrote:
>> Author: dgregor
>> Date: Mon Dec 15 17:53:10 2008
>> New Revision: 61058
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=61058&view=rev
>> Log:
>> Diagnose erroneous uses of out-of-line member definitions and scope
>> specifiers. Specifically: * Determine when an out-of-line
>> function definition does not match
>> any declaration within the class or namespace (including coping
>> with overloaded functions).
>> * Complain about typedefs and parameters that have scope specifiers.
>> * Complain about out-of-line declarations that aren't also
>> definitions.
>> * Complain about non-static data members being declared out-of-line.
>> * Allow cv-qualifiers on out-of-line member function definitions.
>>
>> +/// isNearlyMatchingMemberFunction - Determine whether the C++
>> member
>> +/// functions Declaration and Definition are "nearly" matching. This
>> +/// heuristic is used to improve diagnostics in the case where an
>> +/// out-of-line member function definition doesn't match any
>> +/// declaration within the class.
>> +static bool isNearlyMatchingMemberFunction(ASTContext &Context,
>> + FunctionDecl
>> *Declaration,
>> + FunctionDecl
>> *Definition) {
>> + if (Declaration->param_size() != Definition->param_size())
>> + return false;
>> + for (unsigned Idx = 0; Idx < Declaration->param_size(); ++Idx) {
>> + QualType DeclParamTy = Declaration->getParamDecl(Idx)->getType
>> ();
>> + QualType DefParamTy = Definition->getParamDecl(Idx)->getType();
>> +
>> + DeclParamTy = Context.getCanonicalType
>> (DeclParamTy.getNonReferenceType());
>> + DefParamTy = Context.getCanonicalType
>> (DefParamTy.getNonReferenceType());
>> + if (DeclParamTy.getUnqualifiedType() !=
>> DefParamTy.getUnqualifiedType())
>> + return false;
>> + }
>> +
>> + return true;
>> +}
>> +
>>
> Do we already support cv qualifiers on member functions?
Yes, we do.
> Because that's another thing that's very easy to get wrong and
> deserves a special note in the diagnostic.
For this case, we'll get a "member declaration nearly matches" note.
We could probably detect the case where everything matches exactly
except the cv-qualifiers on the function or even the more narrow case
where the cv-qualifiers are missing [*], and give some diagnostic like
"definition is missing the 'const' qualifier". Do you have wording in
mind for such a diagnostic?
- Doug
[*] I had this happen to me on Friday, which got me interested in
coping with out-of-line definitions better :)
More information about the cfe-commits
mailing list