Skip to content

Red code due to eclipse evaluating SFINAE template incorrectly. #227

Open
@Sporking

Description

@Sporking

I have, for years, had longstanding red code in a project that compiles and runs fine. I eventually isolated an example, and found that even trivial use of std::tuple would cause red code.

For example, in code such as this:

#include <tuple>
int x;
std::tuple<int> tup(x);

'tup' would show as red, when it shouldn't.

Digging further into the header files I was using in Eclipse (those from Cygwin x86-64, for gcc 11), and simplifying header file contents, I simplified the problem to the following:

// Stripped down version of std::true_type
struct True { static constexpr bool value = true; }

// Stripped down version of std::__and_
template<typename B> struct Truthy;
template<typename B> struct Truthy<B> { static constexpr bool value = true;};

// Stripped down version of std::enable_if
template<bool> struct MaybeBool {};
template<> struct MaybeBool<true> { using type = bool; };

// Stripped down version of std::tuple
struct Broken
{
  // Eclipse doesn't seem to be able to figure out that
  // Truthy<int>::value is true, and that therefore
  // MaybeBool<Truthy<int>::value> should expand to 'bool',
  // and that therefore the template becomes "template<bool = true>"
  // which is valid according to SFINAE, and that therefore the
  // constructor should not be removed due to specification failure.
  template<typename MaybeBool< Truthy<int>::value >::type = true>
  Broken(const int& elems) noexcept {}
  
  // Note that uncommenting the following lines will cause the
  // red below to go away.
  //  template<typename MaybeBool< True::value >::type = true>
  //  Broken(const int& elems) noexcept {}
  
  // Note that uncommenting the following lines will cause the
  // red below to go away.
  //  template<typename MaybeBool< true >::type = true>
  //  Broken(const int& elems) noexcept {}
};

int keyCompData = 5;
Broken blarg1(keyCompData);   // blarg1 is red.
Broken blarg2{ keyCompData }; // blarg2 is underlined red.

Metadata

Metadata

Assignees

No one assigned

    Labels

    languageC/C++ Language Support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions