[Sema] Allow casting of some overloaded functions
Some functions can't have their address taken. If we encounter an
overload set where only one of the candidates can have its address
taken, we should automatically select that candidate in cast
expressions.
Differential Revision: http://reviews.llvm.org/D17701
llvm-svn: 263887
diff --git a/clang/test/SemaCXX/unaddressable-functions.cpp b/clang/test/SemaCXX/unaddressable-functions.cpp
new file mode 100644
index 0000000..a382ccf
--- /dev/null
+++ b/clang/test/SemaCXX/unaddressable-functions.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
+
+namespace access_control {
+class Private {
+ void check(int *) __attribute__((enable_if(false, "")));
+ void check(double *) __attribute__((enable_if(true, "")));
+
+ static void checkStatic(int *) __attribute__((enable_if(false, "")));
+ static void checkStatic(double *) __attribute__((enable_if(true, "")));
+};
+
+auto Priv = reinterpret_cast<void (Private::*)(char *)>(&Private::check); // expected-error{{'check' is a private member of 'access_control::Private'}} expected-note@6{{implicitly declared private here}}
+
+auto PrivStatic = reinterpret_cast<void (*)(char *)>(&Private::checkStatic); // expected-error{{'checkStatic' is a private member of 'access_control::Private'}} expected-note@9{{implicitly declared private here}}
+
+class Protected {
+protected:
+ void check(int *) __attribute__((enable_if(false, "")));
+ void check(double *) __attribute__((enable_if(true, "")));
+
+ static void checkStatic(int *) __attribute__((enable_if(false, "")));
+ static void checkStatic(double *) __attribute__((enable_if(true, "")));
+};
+
+auto Prot = reinterpret_cast<void (Protected::*)(char *)>(&Protected::check); // expected-error{{'check' is a protected member of 'access_control::Protected'}} expected-note@19{{declared protected here}}
+
+auto ProtStatic = reinterpret_cast<void (*)(char *)>(&Protected::checkStatic); // expected-error{{'checkStatic' is a protected member of 'access_control::Protected'}} expected-note@22{{declared protected here}}
+}
+
+namespace unavailable {
+// Ensure that we check that the function can be called
+void foo() __attribute__((unavailable("don't call this")));
+void foo(int) __attribute__((enable_if(false, "")));
+
+void *Ptr = reinterpret_cast<void*>(foo); // expected-error{{'foo' is unavailable: don't call this}} expected-note@-3{{explicitly marked unavailable here}}
+}