summaryrefslogtreecommitdiff
path: root/clang/test/CXX/over/over.over
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/over/over.over')
-rw-r--r--clang/test/CXX/over/over.over/p1.cpp94
-rw-r--r--clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp191
-rw-r--r--clang/test/CXX/over/over.over/p2.cpp9
-rw-r--r--clang/test/CXX/over/over.over/p4.cpp20
4 files changed, 314 insertions, 0 deletions
diff --git a/clang/test/CXX/over/over.over/p1.cpp b/clang/test/CXX/over/over.over/p1.cpp
new file mode 100644
index 0000000..10c60da
--- /dev/null
+++ b/clang/test/CXX/over/over.over/p1.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+template<typename T> T f0(T);
+int f0(int);
+
+// -- an object or reference being initialized
+struct S {
+ int (*f0)(int);
+ float (*f1)(float);
+};
+
+void test_init_f0() {
+ int (*f0a)(int) = f0;
+ int (*f0b)(int) = &f0;
+ int (*f0c)(int) = (f0);
+ float (*f0d)(float) = f0;
+ float (*f0e)(float) = &f0;
+ float (*f0f)(float) = (f0);
+ int (&f0g)(int) = f0;
+ int (&f0h)(int) = (f0);
+ float (&f0i)(float) = f0;
+ float (&f0j)(float) = (f0);
+ S s = { f0, f0 };
+}
+
+// -- the left side of an assignment (5.17),
+void test_assign_f0() {
+ int (*f0a)(int) = 0;
+ float (*f0b)(float) = 0;
+
+ f0a = f0;
+ f0a = &f0;
+ f0a = (f0);
+ f0b = f0;
+ f0b = &f0;
+ f0b = (f0);
+}
+
+// -- a parameter of a function (5.2.2),
+void eat_f0(int a(int), float (*b)(float), int (&c)(int), float (&d)(float));
+
+void test_pass_f0() {
+ eat_f0(f0, f0, f0, f0);
+ eat_f0(&f0, &f0, (f0), (f0));
+}
+
+// -- a parameter of a user-defined operator (13.5),
+struct X { };
+void operator+(X, int(int));
+void operator-(X, float(*)(float));
+void operator*(X, int (&)(int));
+void operator/(X, float (&)(float));
+
+void test_operator_pass_f0(X x) {
+ x + f0;
+ x + &f0;
+ x - f0;
+ x - &f0;
+ x * f0;
+ x * (f0);
+ x / f0;
+ x / (f0);
+}
+
+// -- the return value of a function, operator function, or conversion (6.6.3),
+int (*test_return_f0_a())(int) { return f0; }
+int (*test_return_f0_b())(int) { return &f0; }
+int (*test_return_f0_c())(int) { return (f0); }
+float (*test_return_f0_d())(float) { return f0; }
+float (*test_return_f0_e())(float) { return &f0; }
+float (*test_return_f0_f())(float) { return (f0); }
+
+// -- an explicit type conversion (5.2.3, 5.2.9, 5.4), or
+void test_convert_f0() {
+ (void)((int (*)(int))f0);
+ (void)((int (*)(int))&f0);
+ (void)((int (*)(int))(f0));
+ (void)((float (*)(float))f0);
+ (void)((float (*)(float))&f0);
+ (void)((float (*)(float))(f0));
+}
+
+// -- a non-type template-parameter(14.3.2).
+template<int(int)> struct Y0 { };
+template<float(float)> struct Y1 { };
+template<int (&)(int)> struct Y2 { };
+template<float (&)(float)> struct Y3 { };
+
+Y0<f0> y0;
+Y0<&f0> y0a;
+Y1<f0> y1;
+Y1<&f0> y1a;
+Y2<f0> y2;
+Y3<f0> y3;
diff --git a/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp b/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
new file mode 100644
index 0000000..e021711
--- /dev/null
+++ b/clang/test/CXX/over/over.over/p2-resolve-single-template-id.cpp
@@ -0,0 +1,191 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion %s
+
+typedef __typeof__(((int*)0)-((int*)0)) ptrdiff_t;
+
+namespace DontResolveTooEarly_WaitForOverloadResolution
+{
+ template <class T> T* f(int); // #1
+ template <class T, class U> T& f(U); // #2
+
+ void g() {
+ int *ip = f<int>(1); // calls #1
+ }
+
+ template <class T>
+ T* f2(int);
+ template <class T, class U>
+ T& f2(U);
+
+ void g2() {
+ int*ip = (f2<int>)(1); // ok
+ }
+
+} // End namespace
+
+namespace DontAllowUnresolvedOverloadedExpressionInAnUnusedExpression
+{
+ void one() { }
+ template<class T> void oneT() { }
+
+ void two() { } // expected-note 2 {{possible target for call}}
+ void two(int) { } // expected-note 2 {{possible target for call}}
+ template<class T> void twoT() { } // expected-note 2 {{possible target for call}}
+ template<class T> void twoT(T) { } // expected-note 2 {{possible target for call}}
+
+ void check()
+ {
+ one; // expected-warning {{expression result unused}}
+ two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
+ oneT<int>; // expected-warning {{expression result unused}}
+ twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
+ }
+
+ // check the template function case
+ template<class T> void check()
+ {
+ one; // expected-warning {{expression result unused}}
+ two; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
+ oneT<int>; // expected-warning {{expression result unused}}
+ twoT<int>; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
+
+ }
+
+}
+
+ template<typename T>
+ void twoT() { }
+ template<typename T, typename U>
+ void twoT(T) { }
+
+
+ void two() { }; //expected-note 5{{candidate}}
+ void two(int) { }; //expected-note 5{{candidate}}
+
+
+
+ void one() { }
+ template<class T>
+ void oneT() { }
+
+ template<class T>
+ void cant_resolve() { } //expected-note 3{{candidate}}
+
+ template<class T> void cant_resolve(T) { }//expected-note 3{{candidate}}
+
+
+int main()
+{
+
+ { static_cast<void>(one); }
+ { (void)(one); }
+ { static_cast<void>(oneT<int>); }
+ { (void)(oneT<int>); }
+
+ { static_cast<void>(two); } // expected-error {{address of overloaded function 'two' cannot be static_cast to type 'void'}}
+ { (void)(two); } // expected-error {{address of overloaded function 'two' cannot be cast to type 'void'}}
+ { static_cast<void>(twoT<int>); }
+ { (void)(twoT<int>); }
+
+
+ { ptrdiff_t x = reinterpret_cast<ptrdiff_t>(oneT<int>); }
+ { (void) reinterpret_cast<int (*)(char, double)>(oneT<int>); }
+ { (void) reinterpret_cast<ptrdiff_t>(one); }
+ { (void) reinterpret_cast<int (*)(char, double)>(one); }
+
+ { ptrdiff_t x = reinterpret_cast<ptrdiff_t>(twoT<int>); }
+ { (void) reinterpret_cast<int (*)(char, double)>(twoT<int>); }
+ { (void) reinterpret_cast<void (*)(int)>(two); } //expected-error {{reinterpret_cast}}
+ { (void) static_cast<void (*)(int)>(two); } //ok
+
+ { (void) reinterpret_cast<int>(two); } //expected-error {{reinterpret_cast}}
+ { (void) reinterpret_cast<int (*)(char, double)>(two); } //expected-error {{reinterpret_cast}}
+
+ { bool b = (twoT<int>); }
+ { bool b = (twoT<int, int>); }
+
+ { bool b = &twoT<int>; //&foo<int>; }
+ b = &(twoT<int>); }
+
+ { ptrdiff_t x = (ptrdiff_t) &twoT<int>;
+ x = (ptrdiff_t) &twoT<int>; }
+
+ { ptrdiff_t x = (ptrdiff_t) twoT<int>;
+ x = (ptrdiff_t) twoT<int>; }
+
+
+ { ptrdiff_t x = (ptrdiff_t) &twoT<int,int>;
+ x = (ptrdiff_t) &twoT<int>; }
+
+ { oneT<int>; &oneT<int>; } //expected-warning 2{{expression result unused}}
+ { static_cast<void>(cant_resolve<int>); } // expected-error {{address of overload}}
+ { bool b = cant_resolve<int>; } // expected-error {{address of overload}}
+ { (void) cant_resolve<int>; } // expected-error {{address of overload}}
+
+}
+
+namespace member_pointers {
+ struct S {
+ template <typename T> bool f(T) { return false; }
+ template <typename T> static bool g(T) { return false; }
+
+ template <typename T> bool h(T) { return false; } // expected-note 3 {{possible target for call}}
+ template <int N> static bool h(int) { return false; } // expected-note 3 {{possible target for call}}
+ };
+
+ void test(S s) {
+ if (S::f<char>) return; // expected-error {{call to non-static member function without an object argument}}
+ if (S::f<int>) return; // expected-error {{call to non-static member function without an object argument}}
+ if (&S::f<char>) return;
+ if (&S::f<int>) return;
+ if (s.f<char>) return; // expected-error {{reference to non-static member function must be called}}
+ if (s.f<int>) return; // expected-error {{reference to non-static member function must be called}}
+ if (&s.f<char>) return; // expected-error {{cannot create a non-constant pointer to member function}}
+ if (&s.f<int>) return; // expected-error {{cannot create a non-constant pointer to member function}}
+
+ if (S::g<char>) return;
+ if (S::g<int>) return;
+ if (&S::g<char>) return;
+ if (&S::g<int>) return;
+ if (s.g<char>) return;
+ if (s.g<int>) return;
+ if (&s.g<char>) return;
+ if (&s.g<int>) return;
+
+ if (S::h<42>) return;
+ if (S::h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
+ if (&S::h<42>) return;
+ if (&S::h<int>) return;
+ if (s.h<42>) return;
+ if (s.h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
+ if (&s.h<42>) return;
+ if (&s.h<int>) return; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
+
+ { bool b = S::f<char>; } // expected-error {{call to non-static member function without an object argument}}
+ { bool b = S::f<int>; } // expected-error {{call to non-static member function without an object argument}}
+ { bool b = &S::f<char>; }
+ { bool b = &S::f<int>; }
+ // These next two errors are terrible.
+ { bool b = s.f<char>; } // expected-error {{reference to non-static member function must be called}}
+ { bool b = s.f<int>; } // expected-error {{reference to non-static member function must be called}}
+ { bool b = &s.f<char>; } // expected-error {{cannot create a non-constant pointer to member function}}
+ { bool b = &s.f<int>; } // expected-error {{cannot create a non-constant pointer to member function}}
+
+ { bool b = S::g<char>; }
+ { bool b = S::g<int>; }
+ { bool b = &S::g<char>; }
+ { bool b = &S::g<int>; }
+ { bool b = s.g<char>; }
+ { bool b = s.g<int>; }
+ { bool b = &s.g<char>; }
+ { bool b = &s.g<int>; }
+
+ { bool b = S::h<42>; }
+ { bool b = S::h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
+ { bool b = &S::h<42>; }
+ { bool b = &S::h<int>; }
+ { bool b = s.h<42>; }
+ { bool b = s.h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
+ { bool b = &s.h<42>; }
+ { bool b = &s.h<int>; } // expected-error {{can't form member pointer of type 'bool' without '&' and class name}}
+ }
+}
diff --git a/clang/test/CXX/over/over.over/p2.cpp b/clang/test/CXX/over/over.over/p2.cpp
new file mode 100644
index 0000000..3e8d0f1
--- /dev/null
+++ b/clang/test/CXX/over/over.over/p2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<typename T> T f0(T, T); //expected-note{{candidate}}
+
+void test_f0() {
+ int (*f0a)(int, int) = f0;
+ int (*f0b)(int, int) = &f0;
+ int (*f0c)(int, float) = f0; // expected-error{{address of overloaded function 'f0' does not match required type 'int (int, float)'}}
+}
diff --git a/clang/test/CXX/over/over.over/p4.cpp b/clang/test/CXX/over/over.over/p4.cpp
new file mode 100644
index 0000000..27d070e
--- /dev/null
+++ b/clang/test/CXX/over/over.over/p4.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template<typename T> T f0(T); // expected-note{{candidate function}}
+int f0(int); // expected-note{{candidate function}}
+
+void test_f0() {
+ int (*fp0)(int) = f0;
+ int (*fp1)(int) = &f0;
+ float (*fp2)(float) = &f0;
+}
+
+namespace N {
+ int f0(int); // expected-note{{candidate function}}
+}
+
+void test_f0_2() {
+ using namespace N;
+ int (*fp0)(int) = f0; // expected-error{{address of overloaded function 'f0' is ambiguous}}
+ float (*fp1)(float) = f0;
+}