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

Due SAM: The compiler attempts to instantiate a mismatched template specialization #2537

Open
3 tasks done
Ebola-Chan-bot opened this issue Feb 12, 2024 · 2 comments
Open
3 tasks done
Labels
type: imperfection Perceived defect in any part of project

Comments

@Ebola-Chan-bot
Copy link

Describe the problem

C:\Users\vhtmf\Documents\Arduino\sketch_feb10a\sketch_feb10a.ino: In instantiation of 'constexpr const bool _Allow_inheriting_unwrap<unsigned int*, void>::value':
C:\Users\vhtmf\Documents\Arduino\sketch_feb10a\sketch_feb10a.ino:22:70:   required from here
C:\Users\vhtmf\Documents\Arduino\sketch_feb10a\sketch_feb10a.ino:19:25: error: 'unsigned int*' is not a class, struct, or union type
   static constexpr bool value = is_same<_Iter, typename _Iter::_Prevent_inheriting_unwrap>::value;
                         ^

exit status 1

Compilation error: 'unsigned int*' is not a class, struct, or union type

To reproduce

template<class, class>
struct is_same {
  static constexpr bool value = false;  // determine whether arguments are the same type
};
template<class _Ty>
struct is_same<_Ty, _Ty> {
  static constexpr bool value = true;
};

template<class... _Types>
using void_t = void;

template<class _Iter, class = void>
struct _Allow_inheriting_unwrap {
  static constexpr bool value = true;
};
template<class _Iter>
struct _Allow_inheriting_unwrap<_Iter, void_t<typename _Iter::_Prevent_inheriting_unwrap>> {
  static constexpr bool value = is_same<_Iter, typename _Iter::_Prevent_inheriting_unwrap>::value;
};
void setup() {
  constexpr auto BB = _Allow_inheriting_unwrap<unsigned int*, void>::value;
}

void loop() {
  // put your main code here, to run repeatedly:
}

Expected behavior

This code can be compiled in both MSVC and Godbolt. Even in the Arduino IDE, the value of constexpr auto BB is correctly displayed as bool true. But once it enters the compile phase, the compiler mistakenly tries to match the specialized _Allow_inheriting_unwrap and then fails because unsigned int * has no members to reference.

Arduino CLI version

0.35.2

Operating system

Windows

Operating system version

Windows 11

Additional context

This issue only appears on the Arduino Due SAM platform. The AVR platform is normal.

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@Ebola-Chan-bot Ebola-Chan-bot added the type: imperfection Perceived defect in any part of project label Feb 12, 2024
@Ebola-Chan-bot Ebola-Chan-bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@Ebola-Chan-bot
Copy link
Author

Ebola-Chan-bot commented Feb 13, 2024

This may indicate a problem with the compiler's handling of SFINAE.

@Ebola-Chan-bot
Copy link
Author

At present, I need to do the following workaround for void_t:

template<class... _Types>
struct void_s {
  using type = void;
};
template<class T, class... _Types>
struct void_s<T, _Types...> {
  using type = T;
};
template<typename... _Types>
using void_t = typename void_s<_Types...>::type;

If anyone else is having a similar problem, try my workaround idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

1 participant