Skip to content

GCC warning with -Wconversion and undefined behavior for unknown_array_type #1066

Closed

Description

@zbjornson

This line:

static const napi_typedarray_type unknown_array_type = static_cast<napi_typedarray_type>(-1);

causes a warning with -Wconversion enabled:

 warning: the result of the conversion is unspecified because ‘-1’ is outside the range of type ‘napi_typedarray_type’ [-Wconversion]
  911 |     static const napi_typedarray_type unknown_array_type = static_cast<napi_typedarray_type>(-1);
      |

I don't think this is really an issue, but it would be nice to get rid of the warning.

(https://wiki.sei.cmu.edu/confluence/display/cplusplus/INT50-CPP.+Do+not+cast+to+an+out-of-range+enumeration+value)

Activity

  1. mhdawson commented on Sep 8, 2021

    @mhdawson
    Member

    @zbjornson would you like to submit a suggested PR? I'd have to think more about whether changing the value would be a problem or not but I assume there are other ways to suppress the warking as well.

  2. zbjornson commented on Sep 8, 2021

    @zbjornson
    Author

    Sure. I'll take a look at better solutions, but #pragma GCC diagnostics ignored "-Wconversion" would minimally work. The C++ spec defines this enum to have an implicit size of int, which has at least 16 bits, and the enum has 11 members currently, which is why I said it's probably not an issue. However, since C++17 this line is actually undefined behavior, not just an unspecified value.

    node-addon-api could maybe have its own enum that has the same values as napi_typedarray_type plus an unknown type. I think that would be unobtrusive.

  3. github-actions commented on Dec 8, 2021

    @github-actions
    Contributor

    This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

  4. changed the title [-]GCC warning with -Wconversion for unknown_array_type[/-] [+]GCC warning with -Wconversion and undefined behavior for unknown_array_type[/+] on Jan 5, 2022
  5. github-actions commented on Apr 11, 2022

    @github-actions
    Contributor

    This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

  6. mhdawson commented on Apr 12, 2022

    @mhdawson
    Member

    @zbjornson were you still planning to submit a PR on this?

  7. github-actions commented on Jul 12, 2022

    @github-actions
    Contributor

    This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

  8. NickNaso commented on Nov 3, 2022

    @NickNaso
    Member

    I'm closing the issue because it has been solved with PR #1209

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions