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

Add AVR __[u]int24 to type_traits #37

Closed
wants to merge 1 commit into from
Closed

Conversation

kevinpt
Copy link

@kevinpt kevinpt commented Dec 29, 2024

Support the 24-bit integer types __int24 and __uint24 in type_traits.

@jwakely
Copy link

jwakely commented Dec 30, 2024

Why are these not already enabled as __GLIBCXX_TYPE_INT_N_1 ?

That's how non-standard integer types are supposed to be supported, and how it works for other targets.

@kevinpt
Copy link
Author

kevinpt commented Dec 30, 2024 via email

@jwakely
Copy link

jwakely commented Dec 30, 2024

If avr-g++ supports those types, then it should define the macros to tell libstdc++ that it supports them. Then everything in the library will just work.

@kevinpt
Copy link
Author

kevinpt commented Dec 30, 2024

This test program fails to compile with the existing code. It works fine with standard integer types:

  #include <type_traits>

  // Templated function to increment only integral types
  template <typename T>
  typename std::enable_if<std::is_integral<T>::value, T>::type increment(T value) {
      return value + 1;
  }

  bool demo(__int24 n) {
    return increment(n) > n;
  }

avr-g++ -std=c++20 -I lib/avr-libstdcpp/include -c type_traits_bug.cc -o type_traits_bug.o

  ...
  type_traits_bug.cc:5:62: note:   template argument deduction/substitution failed:
  type_traits_bug.cc: In substitution of 'template<class T> typename std::enable_if<std::is_integral<_Tp>::value, T>::type increment(T) [with T = __int24]':
  ...

@jwakely
Copy link

jwakely commented Jan 7, 2025

I think a better fix would be to add this to include/bits/c++config.h

#if defined(__INT24_MAX__) && !defined(__GLIBCXX_TYPE_INT_N_0)
# define __GLIBCXX_TYPE_INT_N_0 __int24
# define __GLIBCXX_BITSIZE_INT_N_0 24
#endif

This will make all the type traits and other metaprogramming utilities work for __int24 and unsigned __int24

I'll file an upstream GCC bug to get those macros implicitly defined by the compiler, which is how it's supposed to work.

Edit: filed https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118329

@kevinpt
Copy link
Author

kevinpt commented Jan 10, 2025

This is the best solution. Thanks for digging into the problem.

@kevinpt kevinpt closed this Jan 10, 2025
@jwakely
Copy link

jwakely commented Jan 17, 2025

The GCC avr maintainer has fixed this for GCC 14.3:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118329

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

Successfully merging this pull request may close these issues.

2 participants