Skip to content

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

Open
@Ebola-Chan-bot

Description

@Ebola-Chan-bot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions