[PATCH] D16949: Fix for: Bug 5941 - improve diagnostic for * vs & confusion
Ryan Yee via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 1 18:55:58 PST 2016
ryee88 updated this revision to Diff 49577.
http://reviews.llvm.org/D16949
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaOverload.cpp
test/SemaCXX/overload-call.cpp
Index: test/SemaCXX/overload-call.cpp
===================================================================
--- test/SemaCXX/overload-call.cpp
+++ test/SemaCXX/overload-call.cpp
@@ -375,16 +375,24 @@
}
// PR 6117
-namespace test3 {
- struct Base {};
+namespace IncompleteConversion {
+ struct Complete {};
struct Incomplete;
- void foo(Base *); // expected-note 2 {{cannot convert argument of incomplete type}}
- void foo(Base &); // expected-note 2 {{cannot convert argument of incomplete type}}
-
- void test(Incomplete *P) {
- foo(P); // expected-error {{no matching function for call to 'foo'}}
- foo(*P); // expected-error {{no matching function for call to 'foo'}}
+ void completeFunction(Complete *); // expected-note 2 {{cannot convert argument of incomplete type}}
+ void completeFunction(Complete &); // expected-note 2 {{cannot convert argument of incomplete type}}
+
+ void testTypeConversion(Incomplete *P) {
+ completeFunction(P); // expected-error {{no matching function for call to 'completeFunction'}}
+ completeFunction(*P); // expected-error {{no matching function for call to 'completeFunction'}}
+ }
+
+ void incompletePointerFunction(Incomplete *); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete' to 'IncompleteConversion::Incomplete *' for 1st argument; take the address of the argument with &}}
+ void incompleteReferenceFunction(Incomplete &); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete *' to 'IncompleteConversion::Incomplete &' for 1st argument; dereference the argument with *}}
+
+ void testPointerReferenceConversion(Incomplete &reference, Incomplete *pointer) {
+ incompletePointerFunction(reference); // expected-error {{no matching function for call to 'incompletePointerFunction'}}
+ incompleteReferenceFunction(pointer); // expected-error {{no matching function for call to 'incompleteReferenceFunction'}}
}
}
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -9104,10 +9104,13 @@
if (const PointerType *PTy = TempFromTy->getAs<PointerType>())
TempFromTy = PTy->getPointeeType();
if (TempFromTy->isIncompleteType()) {
+ // Emit the generic diagnostic and, optionally, add the hints to it.
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_conv_incomplete)
<< (unsigned) FnKind << FnDesc
<< (FromExpr ? FromExpr->getSourceRange() : SourceRange())
- << FromTy << ToTy << (unsigned) isObjectArgument << I+1;
+ << FromTy << ToTy << (unsigned) isObjectArgument << I+1
+ << (unsigned) (Cand->Fix.Kind);
+
MaybeEmitInheritedConstructorNote(S, Fn);
return;
}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3189,7 +3189,12 @@
"function (the implicit move assignment operator)|"
"constructor (inherited)}0%1 "
"not viable: cannot convert argument of incomplete type "
- "%diff{$ to $|to parameter type}2,3">;
+ "%diff{$ to $|to parameter type}2,3 for "
+ "%select{%ordinal5 argument|object argument}4"
+ "%select{|; dereference the argument with *|"
+ "; take the address of the argument with &|"
+ "; remove *|"
+ "; remove &}6">;
def note_ovl_candidate_bad_list_argument : Note<"candidate "
"%select{function|function|constructor|"
"function |function |constructor |"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16949.49577.patch
Type: text/x-patch
Size: 3710 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160302/417736a8/attachment.bin>
More information about the cfe-commits
mailing list