asmaloney/MeshIO

Ambiguous cast in meta-variant conversion

EpicWink opened this issue · 4 comments

On CC build, I get

~/src/CloudCompare/plugins/3rdParty/MeshIO/src/mioUtils.cpp: In function ‘QVariant mioUtils::convertMetaValueToVariant(aiMetadata*, unsigned int)’:
~/src/CloudCompare/plugins/3rdParty/MeshIO/src/mioUtils.cpp:388:25: error: conversion from ‘uint64_t’ {aka ‘long unsigned int’} to ‘QVariant’ is ambiguous
  388 |             metaValue = value;
      |                         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qregularexpression.h:49,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QRegularExpression:1,
                 from ~/src/CloudCompare/plugins/3rdParty/MeshIO/src/mioUtils.cpp:5:

Reproduction
Follow README build instructions

Expected behavior
No build error

Fix
Simply changing the line to metaValue = (qulonglong) value; fixes it

Environment

  • CloudCompare: 6c2993a
  • OS: Ubuntu 19.10
  • Qt: 5.12.4
  • GCC: 9.2.1

Thanks @EpicWink.

There's something that doesn't make sense to me: How is it your compiler thinks that uint64_t is an unsigned long and not an unsigned long long?

(I don't have Linux installed, so I can't poke around.)

Difference in data-model I guess: Unix 64-bit says long is 64 bits, but Windows 64-bit and Unix/Windows 32-bit says long is 32 bits; see Fundamental types and Fixed width integer types.

For me the following

#include<cstdint>

int main(int argc, char** argv) {
    uint64_t *a;
    unsigned long long b[3];
    a = b + 2;
}

Gives me:

int.cpp: In function ‘int main(int, char**)’:
int.cpp:6:11: error: invalid conversion from ‘long long unsigned int*’ to ‘uint64_t*’ {aka ‘long unsigned int*’} [-fpermissive]
    6 |     a = b + 2;
      |         ~~^~~
      |           |
      |           long long unsigned int*

Whereas unsigned long works fine. Likewise:

  • uint32_t needs unsigned int
  • uint16_t needs unsigned short
  • uint8_t needs unsigned char

...and here I was thinking the whole purpose of the cstdint types was cross-platform compatibility. :-(

I don't tend to use them in my own stuff unless I have to interface with things that do... but I'm pretty old school :-)

cstdint types are the same on every platform. It's the fundamental C types which are different for some reason