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

SFINAEing p.x on a pointer wrongly tries to complete the pointee's type #52970

Closed
Quuxplusone opened this issue Jan 3, 2022 · 3 comments
Closed
Assignees
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid

Comments

@Quuxplusone
Copy link
Contributor

This program hard-errors trying to complete Holder<Incomplete>; but it shouldn't.

struct Incomplete;
template<class T> struct Holder { T t; int x; };
template<class T> auto f(T t) -> decltype(t.x);
void f(...);
void test() {
    ::f((Holder<Incomplete>*)nullptr);
}

It appears to me that the problem is here, in LookupMemberExpr:

  // Recover from dot accesses to pointers, e.g.:
  //   type *foo;
  //   foo.bar
  [...]
    if (!IsArrow && Ptr->getPointeeType()->isRecordType() &&
        MemberName.getNameKind() != DeclarationName::CXXDestructorName) {
      S.Diag(OpLoc, diag::err_typecheck_member_reference_suggestion)
          << BaseType << int(IsArrow) << BaseExpr.get()->getSourceRange()
          << FixItHint::CreateReplacement(OpLoc, "->");

      // Recurse as an -> access.
      IsArrow = true;
      return LookupMemberExpr(S, R, BaseExpr, IsArrow, OpLoc, SS,
                              ObjCImpDecl, HasTemplateArgs, TemplateKWLoc);
    }
  }

That second recursive call to LookupMemberExpr triggers completion of the pointed-to type, which is not OK if we're in a SFINAE context.

@Quuxplusone
Copy link
Contributor Author

I've managed to fix this locally by adding

  if (S.isUnevaluatedContext())
    return ExprError();

after the S.Diag; but I don't know if there might be a less blunt instrument available.

@Quuxplusone Quuxplusone self-assigned this Jan 18, 2022
@Quuxplusone
Copy link
Contributor Author

This is now https://reviews.llvm.org/D117603

@Quuxplusone Quuxplusone reopened this Jan 30, 2022
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Feb 1, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 1, 2022

@llvm/issue-subscribers-clang-frontend

mordante pushed a commit that referenced this issue Mar 20, 2024
## Abstract

This pull request removes the `__workaround_52970` concept. This concept
is a workaround for a bug described in #52970, which causes the compiler
to trigger ADL on a pointer to an incomplete type in an SFINAE context.
This bug is fixed in Clang 14.

## Reference

- [[clang] Don't typo-fix an expression in a SFINAE
context](https://reviews.llvm.org/D117603)
- [[libc++] [ranges] ADL-proof the [range.access]
CPOs.](https://reviews.llvm.org/D116239)
chencha3 pushed a commit to chencha3/llvm-project that referenced this issue Mar 23, 2024
## Abstract

This pull request removes the `__workaround_52970` concept. This concept
is a workaround for a bug described in llvm#52970, which causes the compiler
to trigger ADL on a pointer to an incomplete type in an SFINAE context.
This bug is fixed in Clang 14.

## Reference

- [[clang] Don't typo-fix an expression in a SFINAE
context](https://reviews.llvm.org/D117603)
- [[libc++] [ranges] ADL-proof the [range.access]
CPOs.](https://reviews.llvm.org/D116239)
devnexen pushed a commit to devnexen/llvm-project that referenced this issue Mar 23, 2024
## Abstract

This pull request removes the `__workaround_52970` concept. This concept
is a workaround for a bug described in llvm#52970, which causes the compiler
to trigger ADL on a pointer to an incomplete type in an SFINAE context.
This bug is fixed in Clang 14.

## Reference

- [[clang] Don't typo-fix an expression in a SFINAE
context](https://reviews.llvm.org/D117603)
- [[libc++] [ranges] ADL-proof the [range.access]
CPOs.](https://reviews.llvm.org/D116239)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid
Projects
None yet
Development

No branches or pull requests

3 participants