This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Introduce function reference conversion, NFC
ClosedPublic

Authored by aaronpuchert on Sep 3 2019, 10:30 AM.

Details

Summary

Technically 'noexcept' isn't a qualifier, so this should be a separate conversion.

Also add a pure AST test for the conversion.

Diff Detail

Event Timeline

aaronpuchert created this revision.Sep 3 2019, 10:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2019, 10:30 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaronpuchert marked 2 inline comments as done.Sep 3 2019, 10:33 AM

If anyone shares my feeling that the boolean output parameters of CompareReferenceRelationship should rather move to the return value, I would be happy to do that.

clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp
6

This is new.

16

This is also new.

Perhaps I should mention that this fixes an assertion failure.

aaronpuchert planned changes to this revision.Oct 8 2019, 12:53 PM

If anyone shares my feeling that the boolean output parameters of CompareReferenceRelationship should rather move to the return value, I would be happy to do that.

I'll do that in a separate change and then rebase this on top.

aaronpuchert abandoned this revision.Dec 5 2019, 6:25 PM

Already fixed via D66437.

aaronpuchert reclaimed this revision.Feb 26 2020, 5:12 PM
aaronpuchert removed a reviewer: riccibruno.

The diff between both changes might still be interesting.

Rebase on top of D66437.

aaronpuchert retitled this revision from [Sema] Add implicit cast for conversion of function references to [Sema] Introduce function reference conversion.Feb 26 2020, 5:53 PM
aaronpuchert edited the summary of this revision. (Show Details)
aaronpuchert added a reviewer: pcc.
aaronpuchert retitled this revision from [Sema] Introduce function reference conversion to [Sema] Introduce function reference conversion, NFC.Apr 22 2020, 5:10 PM

@rsmith, what do you think about this?

Ping. Maybe this change is too silly, but I think it's better to be precise and not muddle qualification conversions together with casting away noexcept.

rsmith accepted this revision.Nov 16 2020, 6:37 PM

Looks fine as far as it goes, but it looks like we're also missing a cast in function pointer initialization via function conversion:

void f() noexcept;
void (*p)() = f;

results in

|-VarDecl 0x105143e8 <line:2:1, col:15> col:8 p 'void (*)()' cinit
| `-ImplicitCastExpr 0x10514498 <col:15> 'void (*)() noexcept' <FunctionToPointerDecay>
|   `-DeclRefExpr 0x10514450 <col:15> 'void () noexcept' lvalue Function 0x10514240 'f' 'void () noexcept'
This revision is now accepted and ready to land.Nov 16 2020, 6:37 PM

Looks fine as far as it goes, but it looks like we're also missing a cast in function pointer initialization via function conversion:
[...]

|-VarDecl 0x105143e8 <line:2:1, col:15> col:8 p 'void (*)()' cinit
| `-ImplicitCastExpr 0x10514498 <col:15> 'void (*)() noexcept' <FunctionToPointerDecay>
|   `-DeclRefExpr 0x10514450 <col:15> 'void () noexcept' lvalue Function 0x10514240 'f' 'void () noexcept'

It seems to depend on the standard, with -std=c++17:

|-VarDecl p 'void (*)()' cinit
| `-ImplicitCastExpr 'void (*)()' <NoOp>
|   `-ImplicitCastExpr 'void (*)() noexcept' <FunctionToPointerDecay>
|     `-DeclRefExpr 'void () noexcept' lvalue Function 'f' 'void () noexcept'

Perhaps because pre-C++17 noexcept is not part of the type, so we essentially ignore it?

Looks fine as far as it goes, but it looks like we're also missing a cast in function pointer initialization via function conversion:
[...]

|-VarDecl 0x105143e8 <line:2:1, col:15> col:8 p 'void (*)()' cinit
| `-ImplicitCastExpr 0x10514498 <col:15> 'void (*)() noexcept' <FunctionToPointerDecay>
|   `-DeclRefExpr 0x10514450 <col:15> 'void () noexcept' lvalue Function 0x10514240 'f' 'void () noexcept'

It seems to depend on the standard, with -std=c++17:

|-VarDecl p 'void (*)()' cinit
| `-ImplicitCastExpr 'void (*)()' <NoOp>
|   `-ImplicitCastExpr 'void (*)() noexcept' <FunctionToPointerDecay>
|     `-DeclRefExpr 'void () noexcept' lvalue Function 'f' 'void () noexcept'

Perhaps because pre-C++17 noexcept is not part of the type, so we essentially ignore it?

Oh, right, my bad. I forgot we still default to C++14 :)

This revision was automatically updated to reflect the committed changes.
clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p4-ast.cpp