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

GCC warns -Wnon-template-friend on LLVM #67942

Open
danakj opened this issue Oct 2, 2023 · 2 comments
Open

GCC warns -Wnon-template-friend on LLVM #67942

danakj opened this issue Oct 2, 2023 · 2 comments

Comments

@danakj
Copy link
Contributor

danakj commented Oct 2, 2023

Clang does not have this warning but GCC is finding this mistake in LLVM 18 due to a recent change.

/usr/lib/llvm-18/include/llvm/ADT/PagedVector.h:213:59: warning: friend declaration ‘bool llvm::operator==(const PagedVector<T, PageSize>::MaterializedIterator&, const PagedVector<T, PageSize>::MaterializedIterator&)’ declares a non-template function [-Wnon-template-friend]
  213 |                            MaterializedIterator const &RHS);
      |                                                           ^
/usr/lib/llvm-18/include/llvm/ADT/PagedVector.h:213:59: note: (if this is not what you intended, make sure the function template has already been declared and add ‘<>’ after the function name here)
/usr/lib/llvm-18/include/llvm/ADT/PagedVector.h:215:59: warning: friend declaration ‘bool llvm::operator!=(const PagedVector<T, PageSize>::MaterializedIterator&, const PagedVector<T, PageSize>::MaterializedIterator&)’ declares a non-template function [-Wnon-template-friend]
  215 |                            MaterializedIterator const &RHS);
      |                                                           ^
@shafik
Copy link
Collaborator

shafik commented Oct 2, 2023

CC @ktf @zygoloid @AaronBallman

@ktf
Copy link
Contributor

ktf commented Oct 2, 2023

I am not sure how to fix that, frankly. If I drop the friend forward declaration in MaterializedIterator, the error goes away on Linux, but then XCode 15 complains with:

In file included from /Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/unittests/ADT/PagedVectorTest.cpp:13:
/Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/include/llvm/ADT/PagedVector.h:224:16: error: 'PV' is a private member of 'llvm::PagedVector<int, 10>::MaterializedIterator'
    assert(LHS.PV == RHS.PV);
               ^
/Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/include/llvm/ADT/PagedVector.h:240:18: note: in instantiation of member function 'llvm::operator==' requested here
    return !(LHS == RHS);
                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__iterator/distance.h:35:20: note: in instantiation of member function
'llvm::operator!=' requested here
    for (; __first != __last; ++__first)
                   ^
/Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/include/llvm/ADT/PagedVector.h:175:24: note: implicitly declared private here
    const PagedVector *PV;
                       ^
/Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/include/llvm/ADT/PagedVector.h:224:26: error: 'PV' is a private member of 'llvm::PagedVector<int, 10>::MaterializedIterator'
    assert(LHS.PV == RHS.PV);
                         ^
/Users/ktf/src/sw/SOURCES/llvm-upstream/master/0/llvm/include/llvm/ADT/PagedVector.h:175:24: note: implicitly declared private here
    const PagedVector *PV;
                       ^

If I inline the operators like in #67958, it works on macOS and Linux (both clang and GCC), however it fails in the Windows CI.

marxin added a commit to marxin/cvise that referenced this issue Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants