r336475 - Check returned type is valid before using it.

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 14:47:42 PDT 2018


Thanks for the fix!

Though maybe this isn't the best diagnostic experience - given that 'bar'
isn't technically an overloaded function, but is a function template -
worth doing something more precise here? (maybe not)

Wonder if there's similar handling for other diagnostic cases that could be
used here (whether there's something that handles the equivalent: auto *f =
&bar; situation with a better diagnostic & whether that infrastructure
could be reused here)

On Fri, Jul 6, 2018 at 5:22 PM Richard Trieu via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: rtrieu
> Date: Fri Jul  6 17:17:25 2018
> New Revision: 336475
>
> URL: http://llvm.org/viewvc/llvm-project?rev=336475&view=rev
> Log:
> Check returned type is valid before using it.
>
> Add a .isNull() check to returned QualType.  Fixes PR38077
>
> Modified:
>     cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
>     cfe/trunk/test/SemaCXX/overloaded-name.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp?rev=336475&r1=336474&r2=336475&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp Fri Jul  6 17:17:25 2018
> @@ -846,6 +846,9 @@ bool Sema::ActOnCXXNestedNameSpecifierDe
>    assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
>
>    QualType T = BuildDecltypeType(DS.getRepAsExpr(),
> DS.getTypeSpecTypeLoc());
> +  if (T.isNull())
> +    return true;
> +
>    if (!T->isDependentType() && !T->getAs<TagType>()) {
>      Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
>        << T << getLangOpts().CPlusPlus;
>
> Modified: cfe/trunk/test/SemaCXX/overloaded-name.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-name.cpp?rev=336475&r1=336474&r2=336475&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/overloaded-name.cpp (original)
> +++ cfe/trunk/test/SemaCXX/overloaded-name.cpp Fri Jul  6 17:17:25 2018
> @@ -28,3 +28,11 @@ namespace rdar9623945 {
>      }
>    };
>  }
> +
> +namespace PR38077 {
> +  template <class T> void bar() {} // expected-note {{possible target for
> call}}
> +
> +  int run() {
> +    decltype(bar)::does_not_exist; // expected-error {{reference to
> overloaded function could not be resolved; did you mean to call it?}}
> +  }
> +}
>
>
> _______________________________________________
> 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/20180709/643e222c/attachment.html>


More information about the cfe-commits mailing list