Author: rsmith Date: Sun Oct 6 11:40:59 2019 New Revision: 373862 URL: http://llvm.org/viewvc/llvm-project?rev=373862&view=rev Log: [Sema] Avoids an assertion failure when an invalid conversion declaration is used
Summary: When using a user-defined conversion function template with a deduced return type the compiler gives a set of warnings: ``` bug.cc:252:44: error: cannot specify any part of a return type in the declaration of a conversion function; use an alias template to declare a conversion to 'auto (Ts &&...) const' template <typename... Ts> operator auto()(Ts &&... xs) const; ^~~~~~~~~~~~~~~~~~~ bug.cc:252:29: error: conversion function cannot convert to a function type template <typename... Ts> operator auto()(Ts &&... xs) const; ^ error: pointer to function type cannot have 'const' qualifier ``` after which it triggers an assertion failure. It seems the last error is incorrect and doesn't have any location information. This patch stops the compilation after the second warning. Fixes bug 31422. Patch by Mark de Wever! Reviewers: rsmith Reviewed By: rsmith Subscribers: bbannier, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64820 Added: cfe/trunk/test/SemaCXX/PR31422.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=373862&r1=373861&r2=373862&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 6 11:40:59 2019 @@ -8206,6 +8206,9 @@ static FunctionDecl *CreateNewFunctionDe } SemaRef.CheckConversionDeclarator(D, R, SC); + if (D.isInvalidType()) + return nullptr; + IsVirtualOkay = true; return CXXConversionDecl::Create( SemaRef.Context, cast<CXXRecordDecl>(DC), D.getBeginLoc(), NameInfo, R, Added: cfe/trunk/test/SemaCXX/PR31422.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR31422.cpp?rev=373862&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/PR31422.cpp (added) +++ cfe/trunk/test/SemaCXX/PR31422.cpp Sun Oct 6 11:40:59 2019 @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s + +// expected-error@+3 {{cannot specify any part of a return type in the declaration of a conversion function; use an alias template to declare a conversion to 'auto (Ts &&...) const'}} +// expected-error@+2 {{conversion function cannot convert to a function type}} +struct S { + template <typename... Ts> operator auto()(Ts &&... xs) const; +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits