This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Classify conversions from enum to float as narrowing
ClosedPublic

Authored by miyuki on Jan 25 2018, 8:55 AM.

Details

Summary

According to [dcl.init.list]p7:

A narrowing conversion is an implicit conversion
- ...
- from an integer type or unscoped enumeration type to a
  floating-point type, except where the source is a constant
  expression and the actual value after conversion will fit into
  the target type and will produce the original value when
  converted back to the original type, or
- ...

Currently clang does not handle the 'unscoped enumeration' case. This
patch fixes the corresponding check.

Diff Detail

Repository
rC Clang

Event Timeline

miyuki created this revision.Jan 25 2018, 8:55 AM

I understand you're fixing the narrowing check from "unscoped enum/integer type" → float.

But you have also extended some tests which are "unscoped enum" → integer type (lines 153, 170 and 173). So I presume they were already handled correctly before your patch. Can these be submitted separatedly?

miyuki updated this revision to Diff 132974.Feb 6 2018, 5:15 AM

Removed the changes that are unrelated to the 'enum->float' case from the test.

rogfer01 accepted this revision.Feb 16 2018, 9:04 AM

Looks good to me now. Wait a couple of days before submitting it just in case the other reviewers have more comments.

Do you plan to submit (in another change) the unscoped enum → integer type testcases? If this is not currently tested anywhere I think it may be a good thing to have them too.

This revision is now accepted and ready to land.Feb 16 2018, 9:04 AM

Do you plan to submit (in another change) the unscoped enum → integer type testcases? If this is not currently tested anywhere I think it may be a good thing to have them too.

Yes, I'll submit them in a follow-up patch.

This revision was automatically updated to reflect the committed changes.