Page MenuHomePhabricator

[Sema] Avoids an assertion failure when an invalid conversion declaration is used
ClosedPublic

Authored by Mordante on Jul 16 2019, 2:22 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

Mordante created this revision.Jul 16 2019, 2:22 PM
lebedev.ri retitled this revision from Avoids an assertion failure when an invalid conversion declaration is used to [Sema] Avoids an assertion failure when an invalid conversion declaration is used.Aug 17 2019, 6:04 AM
rsmith added inline comments.Aug 29 2019, 1:31 PM
clang/test/Sema/conversion_function_to_function.cpp
1 ↗(On Diff #210171)

Use %clang_cc1 -verify instead of not %clang_cc1 | FileCheck

1 ↗(On Diff #210171)

This test should also live in test/SemaCXX, not test/Sema, because it's C++-specific.

9 ↗(On Diff #210171)

(You don't need this final CHECK line: not %clang_cc1 still fails if clang crashes.)

Mordante updated this revision to Diff 218213.Aug 31 2019, 4:35 AM

Addresses the review remarks:

  • Moved the unit test to SemaCXX (also use the PR as name of the file)
  • Change the unit test to use -verify instead of FileCheck
rsmith accepted this revision.Fri, Oct 4, 11:12 AM

LGTM

This revision is now accepted and ready to land.Fri, Oct 4, 11:12 AM

Thanks for the review. Can you commit the patch since I don't have commit access?

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSun, Oct 6, 11:40 AM