https://bugs.llvm.org/show_bug.cgi?id=42513

Andy Gibbs <andyg1...@hotmail.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #3 from Andy Gibbs <andyg1...@hotmail.co.uk> ---
Hi again,  I've been reviewing the fix for this bug and it seems it is still
incomplete, unfortunately.  Therefore, with your permission, I have re-opened
the bug.

The following is another code sample that was broken by commit r350505 but in
this case not fixed by commit r369384.  Again, the code sample compiled
correctly in clang 7.0 and compiles correctly in gcc.

/*******************************************************************/
template <typename X>
struct Instance
  {
  constexpr Instance(decltype(nullptr)) : x(nullptr) { }

  explicit constexpr operator bool() const
    { return (x != nullptr); }

  constexpr const X* operator->() const
    { return x; }

  private:
  constexpr Instance(const X* x) : x(x) { }

  friend constexpr auto GetInstanceImpl(X*)
    { return +[](){ return Instance<X>(&instance); }; }

  const X* x;
  static constexpr X instance { };
  };


struct GetInstanceHelper
  {
  template <typename Y, auto Ret = GetInstanceImpl((Y*)nullptr)>
  static constexpr auto GetInstance(Y*)
    { return Ret; }

  template <typename Y>
  static constexpr auto GetInstance(...)
    { return nullptr; }
  };

template <typename X>
static constexpr Instance<X> GetInstance()
  {
  constexpr auto i = GetInstanceHelper::GetInstance<X>(0);
  if constexpr (i != nullptr)
    return i();
  else
    return nullptr;
  }


struct X1
  {
  constexpr X1() { }
  friend constexpr auto GetInstanceImpl(X1*);
  constexpr int getValue() const
    { return 7; }
  };

template struct Instance<X1>;


constexpr int test()
  {
  int value = 0;
  if (auto i = GetInstance<X1>())
    value += i->getValue();
  return value;
  }

static_assert(test() == 7, "oops");
/*******************************************************************/

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to