[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-06-12 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334569: [Sema] When the address of a member function is used 
as a template (authored by ahatanak, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D36918?vs=148334=151102#toc

Repository:
  rC Clang

https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  test/SemaCXX/access.cpp


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,50 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function template 
not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+
+  // r325321 caused an assertion failure when the following code was compiled.
+  class A {
+template  static bool foo1() { return true; }
+
+  public:
+void init(bool c) {
+  if (c) {
+auto f = foo1;
+  }
+}
+  };
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3803,10 +3803,16 @@
   return Result;
   }
 
+  // Capture the context in which the function call is made. This is the 
context
+  // that is needed when the accessibility of template arguments is checked.
+  DeclContext *CallingCtx = CurContext;
+
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  , PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  , PartialOverloading, [&, CallingCtx]() {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,50 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function template not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+
+  // r325321 caused an assertion failure when the following code was compiled.
+  class A {
+template  static bool foo1() { return true; }
+
+  public:
+void init(bool c) {
+  if (c) {
+auto f = foo1;
+  }
+}
+  };
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3803,10 +3803,16 @@
   return Result;
   }
 
+  // Capture the context in which the function call is made. This is the context
+  // that is needed when the accessibility of template arguments is checked.
+  DeclContext *CallingCtx = CurContext;
+
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  , PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  , PartialOverloading, [&, CallingCtx]() {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-06-04 Thread Jan Korous via Phabricator via cfe-commits
jkorous accepted this revision.
jkorous added a comment.

LGTM.

Thank you for the explanation!


Repository:
  rC Clang

https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-05-31 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

It doesn't look like it's possible to get the context needed to do 
accessibility check (CXXMethodDecl 'method' for 'C::overloadedMethod' in the 
test case) from 'Expr *OvlExpr' in CheckAddressOfMemberAccess. It's possible to 
get the class in which the member is defined (class ''C' for 
C::overloadedMethod'), but we want the context in which the member is used 
(that is 'method').


Repository:
  rC Clang

https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-05-31 Thread Jan Korous via Phabricator via cfe-commits
jkorous added a comment.

I don't particularly like that between setting the DeclContext 
(SemaTemplateDeduction.cpp:3814) and actually using it (CheckAccess() in 
SemaAccess.cpp:1459) are some 20 stack frames but it looks like you already 
tried fixing this "locally" in your initial approach.

I assume we can't get the appropriate DeclContext from Expr *OvlExpr in 
CheckAddressOfMemberAccess(), right?


Repository:
  rC Clang

https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-05-31 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


Repository:
  rC Clang

https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-05-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 148334.
ahatanak added a comment.

Add a test case for the Chromium failure. Also, simplify a bit by capturing the 
calling context in Sema::DeduceTemplateArguments.


Repository:
  rC Clang

https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  test/SemaCXX/access.cpp


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,50 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+
+  // r325321 caused an assertion failure when the following code was compiled.
+  class A {
+template  static bool foo1() { return true; }
+
+  public:
+void init(bool c) {
+  if (c) {
+auto f = foo1;
+  }
+}
+  };
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3803,10 +3803,17 @@
   return Result;
   }
 
+  // Capture the context in which the function call is made. This is the 
context
+  // that is needed when the accessibility of a class member used as a template
+  // argument is checked.
+  DeclContext *CallingCtx = CurContext;
+
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  , PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  , PartialOverloading, [&, CallingCtx]() {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,50 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+
+  // r325321 caused an assertion failure when the following code was compiled.
+  class A {
+template  static bool foo1() { return true; }
+
+  public:
+void init(bool c) {
+  if (c) {
+auto f = foo1;
+  }
+}
+  };
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3803,10 +3803,17 @@
   return Result;
   }
 
+  // Capture the context in which the function call is made. This is the context
+  // that is needed when the accessibility of a class member used as a template
+  // argument is checked.
+  DeclContext *CallingCtx = CurContext;
+
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  , PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  , PartialOverloading, [&, CallingCtx]() {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk resigned from this revision.
rnk added a comment.

I don't see a new test case for the issue reduced out of Chromium. I'd 
recommend adding that.

I have to resign because I don't know enough about deduction to stamp this...


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-26 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-19 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 138066.
ahatanak added a comment.

The new patch passes the calling context to CheckNonDependent so that 
Sema::CheckAddressOfMemberAccess uses the correct context to check 
accessibility of explicit template arguments. I initially tried moving the 
declaration of SavedContext in Sema::FinishTemplateArgumentDeduction to after 
the call to CheckNonDependent, but that caused 
test/SemaCXX/cxx1z-class-template-argument-deduction.cpp to fail. It seems like 
it changes the way lookup of default template arguments is done when the 
context (which is a CXXDeductionGuideDecl in the failing test case) is not set 
before ConvertDeducedTemplateArguments is called.


https://reviews.llvm.org/D36918

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplateDeduction.cpp
  test/SemaCXX/access.cpp

Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -3170,7 +3170,8 @@
 unsigned NumExplicitlySpecified, FunctionDecl *,
 TemplateDeductionInfo ,
 SmallVectorImpl const *OriginalCallArgs,
-bool PartialOverloading, llvm::function_ref CheckNonDependent) {
+bool PartialOverloading,
+llvm::function_ref CheckNonDependent) {
   // Unevaluated SFINAE context.
   EnterExpressionEvaluationContext Unevaluated(
   *this, Sema::ExpressionEvaluationContext::Unevaluated);
@@ -3185,6 +3186,7 @@
   if (Inst.isInvalid())
 return TDK_InstantiationDepth;
 
+  DeclContext *CallingCtx = CurContext;
   ContextRAII SavedContext(*this, FunctionTemplate->getTemplatedDecl());
 
   // C++ [temp.deduct.type]p2:
@@ -3206,7 +3208,7 @@
   //   P with a type that was non-dependent before substitution of any
   //   explicitly-specified template arguments, if the corresponding argument
   //   A cannot be implicitly converted to P, deduction fails.
-  if (CheckNonDependent())
+  if (CheckNonDependent(CallingCtx))
 return TDK_NonDependentConversionFailure;
 
   // Form the template argument list from the deduced template arguments.
@@ -3799,8 +3801,10 @@
 
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  , PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  , PartialOverloading, [&](DeclContext *CallingCtx) {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -6927,7 +6927,8 @@
   sema::TemplateDeductionInfo ,
   SmallVectorImpl const *OriginalCallArgs = nullptr,
   bool PartialOverloading = false,
-  llvm::function_ref CheckNonDependent = []{ return false; });
+  llvm::function_ref CheckNonDependent =
+  [](DeclContext *){ return false; });
 
   TemplateDeductionResult DeduceTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-03-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak reopened this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

The patch got reverted in r325335 as it broke the Chromium build. I'm reopening 
this review.


Repository:
  rC Clang

https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-02-16 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325321: [Sema] Take into account the current context when 
checking the (authored by ahatanak, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaCXX/access.cpp


Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+  ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 
Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+}


Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+  ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 
Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2018-02-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM, I didn't find any issues


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-12-08 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-10-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 118119.
ahatanak added a comment.

Address review comments.


https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaCXX/access.cpp


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+  ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+  ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-10-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/Sema/SemaAccess.cpp:1798
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;

Rakete wrote:
> You don't need that scope resolution operator there. Also, I guess you don't 
> have to create `EC`, you can just pass 
> `EffectiveContext(CurScope->getEntity())` directly to `IsAccessible`.
The scope resolution operator is needed here because IsAccessible's return type 
is AccessResult defined at the top of SemaAccess.cpp, not the one defined in 
Sema.h. If I remove the scope resolution operator, clang issues a warning 
("comparison of two values with different enumeration types").

EffectiveContext is passed as a temporary now as you suggested.


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-10-06 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete added inline comments.



Comment at: lib/Sema/SemaAccess.cpp:1798
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;

You don't need that scope resolution operator there. Also, I guess you don't 
have to create `EC`, you can just pass 
`EffectiveContext(CurScope->getEntity())` directly to `IsAccessible`.


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-10-06 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-09-29 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D36918



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-08-18 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 111805.
ahatanak added a comment.

Test access to protected member functions.


https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaCXX/access.cpp


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+func2(); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,38 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2();
+  func2();
+}
+  };
+
+  void friendFunc() {
+func2();
+func2();
+  }
+
+  void nonFriendFunc() {
+func2(); // expected-error {{no matching function for call to 'func2'}}
+func2(); // expected-error {{no matching function for call to 'func2'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36918: [Sema] Take into account the current context when checking the accessibility of a member function pointer

2017-08-18 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.

Sema::CheckAddressOfMemberAccess was disregarding the context in which the 
member pointer was referenced.

This patch fixes PR32898.

rdar://problem/33737747


https://reviews.llvm.org/D36918

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaCXX/access.cpp


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,29 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1(void(*fn)()) {} // expected-note {{candidate function not viable: 
no overload of 'func0' matching 'void (*)()' for 1st argument}}
+
+  class C {
+friend void friendFunc();
+void overloadedMethod();
+  public:
+void overloadedMethod(int);
+void method() {
+  func1();
+}
+  };
+
+  void friendFunc() {
+func1();
+  }
+
+  void nonFriendFunc() {
+func1(); // expected-error {{no 
matching function for call to 'func1'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 


Index: test/SemaCXX/access.cpp
===
--- test/SemaCXX/access.cpp
+++ test/SemaCXX/access.cpp
@@ -169,3 +169,29 @@
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1(void(*fn)()) {} // expected-note {{candidate function not viable: no overload of 'func0' matching 'void (*)()' for 1st argument}}
+
+  class C {
+friend void friendFunc();
+void overloadedMethod();
+  public:
+void overloadedMethod(int);
+void method() {
+  func1();
+}
+  };
+
+  void friendFunc() {
+func1();
+  }
+
+  void nonFriendFunc() {
+func1(); // expected-error {{no matching function for call to 'func1'}}
+  }
+}
Index: lib/Sema/SemaAccess.cpp
===
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -1793,6 +1793,11 @@
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  EffectiveContext EC(CurScope->getEntity());
+  if (IsAccessible(*this, EC, Entity) == ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits