Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined references to .name() and .abbreviation() #298

Open
Elbereth9001 opened this issue Nov 4, 2022 · 0 comments
Open

Undefined references to .name() and .abbreviation() #298

Elbereth9001 opened this issue Nov 4, 2022 · 0 comments

Comments

@Elbereth9001
Copy link

Invoking any of the following:

  • units::name(v)
  • units::abbreviation(v)
  • v.name()
  • v.abbreviation()

produces an unreadable mess of a linker error, when:

  • The function is not invoked during compile-time (v is not constexpr, in my original case reading from a .json file...)
  • And v is either a scalar_t or a more complex unit type (failing types commented out in print_dynamic() in attached file)

Invoking these for constexpr values turns them into compile-time errors of the functions being "used but never defined".
I take it that this behaviour is intentional? The only reference I've found to this is in the release notes of 2.3.0:

  • Adds std::cout support for units with no defined abbreviation (they show up as a combination of SI base units)

But there is no further information on why they would not be defined. Since the whole point of the library is about being safe at compile-time, I would expect that the abbreviation could also be constructed at compile-time, since all of the types are known at compile-time. Obviously the name does not always exist for all unit combinations.

Would it be feasible to have one or more of the following?

  • Also have the compilation failure (with a good error message) on non-constexpr values, instead of letting it get to link step?
  • Abbreviation available at compile-time, name empty if not available, would require string-like constexpr objects?
  • scalar.name() == "scalar", scalar.abbreviation() == "" / dimensionless.name() == "dimensionless", dimensionless.abbreviation() == "", unless something more special exists, such as for decibels?

Tested with:
Units 2.3.1, Clang 14.0
Units 2.3.3, GCC 9.4.0

Unreadable linker error:
linker_error

Compile-time error:
compiler_error

Code:
maincpp.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant