[PATCH] D64820: Avoids an assertion failure when an invalid conversion declaration is used

Mark de Wever via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 16 14:24:17 PDT 2019


Mordante created this revision.
Mordante added a reviewer: rsmith.
Mordante added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64820

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/conversion_function_to_function.cpp


Index: clang/test/Sema/conversion_function_to_function.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/conversion_function_to_function.cpp
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 -fsyntax-only -std=c++14 %s 2>&1 | FileCheck %s
+
+struct S {
+  template <typename... Ts> operator auto()(Ts &&... xs) const;
+};
+
+// CHECK: 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'
+// CHECK: error: conversion function cannot convert to a function type
+// CHECK-NOT: Assertion{{.*}}failed
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8066,6 +8066,9 @@
     }
 
     SemaRef.CheckConversionDeclarator(D, R, SC);
+    if (D.isInvalidType())
+      return nullptr;
+
     IsVirtualOkay = true;
     return CXXConversionDecl::Create(
         SemaRef.Context, cast<CXXRecordDecl>(DC), D.getBeginLoc(), NameInfo, R,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64820.210171.patch
Type: text/x-patch
Size: 1104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190716/be82d0ef/attachment.bin>


More information about the cfe-commits mailing list