[PATCH] D16949: Fix for: Bug 5941 - improve diagnostic for * vs & confusion

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 16 22:45:58 PST 2016


On Tue, Feb 16, 2016 at 10:01 PM, Ryan Yee via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> ryee88 updated this revision to Diff 48149.
> ryee88 added a comment.
>
> Keeping the number of test files to a minimum makes sense.
>
> Couldn't find an existing test for this diagnostic.


That would be a bit surprising - if you want to see if you can find one,
one way would be to add an "assert(false)" in where the diagnostic is
emitted, and see which test cases fail - see if any look useful. They might
not be testing tnhe whole diagnostic text, etc, but could be expanded to do
so.


> I did find a cxx-reference.cpp that tests reference diagnostics so this
> seems like a reasonable location for this new test.
>
>
> http://reviews.llvm.org/D16949
>
> Files:
>   include/clang/Basic/DiagnosticSemaKinds.td
>   lib/Sema/SemaOverload.cpp
>   test/Parser/cxx-reference.cpp
>
> Index: test/Parser/cxx-reference.cpp
> ===================================================================
> --- test/Parser/cxx-reference.cpp
> +++ test/Parser/cxx-reference.cpp
> @@ -24,3 +24,29 @@
>  #if __cplusplus <= 199711L
>  // expected-warning at -2 {{rvalue references are a C++11 extension}}
>  #endif
> +
> +namespace PointerVsReferenceSuggestion{
> +  class A;
> +
> +  void f0(A *a); // expected-note {{candidate function not viable: cannot
> convert argument of incomplete type 'PointerVsReferenceSuggestion::A' to
> 'PointerVsReferenceSuggestion::A *' for 1st argument; take the address of
> the argument with &}}
> +  void f1(A &a) {
> +    f0(a); // expected-error {{no matching function for call to 'f0'}}
> +  }
> +
> +  void f2(A &a); // expected-note {{candidate function not viable: cannot
> convert argument of incomplete type 'PointerVsReferenceSuggestion::A *' to
> 'PointerVsReferenceSuggestion::A &' for 1st argument; dereference the
> argument with *}}
> +  void f3(A *a) {
> +    f2(a); // expected-error {{no matching function for call to 'f2'}}
> +  }
> +
> +  class B {};
> +
> +  void f4(B *b); // expected-note {{candidate function not viable: no
> known conversion from 'PointerVsReferenceSuggestion::B' to
> 'PointerVsReferenceSuggestion::B *' for 1st argument; take the address of
> the argument with &}}
> +  void f5(B &b) {
> +    f4(b); // expected-error {{no matching function for call to 'f4'}}
> +  }
> +
> +  void f6(B &b); // expected-note {{candidate function not viable: no
> known conversion from 'PointerVsReferenceSuggestion::B *' to
> 'PointerVsReferenceSuggestion::B &' for 1st argument; dereference the
> argument with *}}
> +  void f7(B *b) {
> +    f6(b); // expected-error {{no matching function for call to 'f6'}}
> +  }
> +}
> 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 |"
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160216/d580b428/attachment.html>


More information about the cfe-commits mailing list