[llvm-bugs] [Bug 42513] Friend function declarations hidden in qualifed name lookup (regression introduced by commit r350505)

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 30 15:56:03 PDT 2020


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

Andy Gibbs <andyg1001 at hotmail.co.uk> changed:

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

--- Comment #3 from Andy Gibbs <andyg1001 at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201030/61528cd3/attachment-0001.html>


More information about the llvm-bugs mailing list