summaryrefslogtreecommitdiff
path: root/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default')
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp16
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p2.cpp9
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p3.cpp13
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp55
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p5.cpp19
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p6.cpp33
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp7
-rw-r--r--clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp4
8 files changed, 156 insertions, 0 deletions
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp
new file mode 100644
index 0000000..385e45d
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct A {
+ virtual void f(int a = 7);
+};
+
+struct B : public A {
+ void f(int a); // expected-note{{'f' declared here}}
+};
+
+void m() {
+ B* pb = new B;
+ A* pa = pb;
+ pa->f(); // OK, calls pa->B::f(7)
+ pb->f(); // expected-error{{too few arguments}}
+}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p2.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p2.cpp
new file mode 100644
index 0000000..0a107eb
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p2.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void point(int = 3, int = 4);
+
+void test_point() {
+ point(1,2);
+ point(1);
+ point();
+}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p3.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p3.cpp
new file mode 100644
index 0000000..e9c5e0c
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p3.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void nondecl(int (*f)(int x = 5)) // {expected-error {{default arguments can only be specified}}}
+{
+ void (*f2)(int = 17) // {expected-error {{default arguments can only be specified}}}
+ = (void (*)(int = 42))f; // {expected-error {{default arguments can only be specified}}}
+}
+
+struct X0 {
+ int (*f)(int = 17); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
+
+ void mem8(int (*fp)(int) = (int (*)(int = 17))0); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
+};
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
new file mode 100644
index 0000000..f3dec52
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f0(int i, int j, int k = 3);
+void f0(int i, int j, int k);
+void f0(int i, int j = 2, int k);
+void f0(int i, int j, int k);
+void f0(int i = 1, // expected-note{{previous definition}}
+ int j, int k);
+void f0(int i, int j, int k);
+
+namespace N0 {
+ void f0(int, int, int); // expected-note{{candidate}}
+
+ void test_f0_inner_scope() {
+ f0(); // expected-error{{no matching}}
+ }
+}
+
+void test_f0_outer_scope() {
+ f0(); // okay
+}
+
+void f0(int i = 1, // expected-error{{redefinition of default argument}}
+ int, int);
+
+template<typename T> void f1(T); // expected-note{{previous}}
+
+template<typename T>
+void f1(T = T()); // expected-error{{cannot be added}}
+
+
+namespace N1 {
+ // example from C++03 standard
+ // FIXME: make these "f2"s into "f"s, then fix our scoping issues
+ void f2(int, int);
+ void f2(int, int = 7);
+ void h() {
+ f2(3); // OK, calls f(3, 7)
+ void f(int = 1, int); // expected-error{{missing default argument}}
+ }
+
+ void m()
+ {
+ void f(int, int); // expected-note{{'f' declared here}}
+ f(4); // expected-error{{too few arguments to function call}}
+ void f(int, int = 5); // expected-note{{previous definition}}
+ f(4); // okay
+ void f(int, int = 5); // expected-error{{redefinition of default argument}}
+ }
+
+ void n()
+ {
+ f2(6); // okay
+ }
+}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p5.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p5.cpp
new file mode 100644
index 0000000..3100e56
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p5.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+float global_f;
+
+void f0(int *ip = &global_f); // expected-error{{cannot initialize}} \
+// expected-note{{passing argument to parameter 'ip' here}}
+
+// Example from C++03 standard
+int a = 1;
+int f(int);
+int g(int x = f(a));
+
+void h() {
+ a = 2;
+ {
+ int *a = 0;
+ g(); // FIXME: check that a is called with a value of 2
+ }
+}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p6.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p6.cpp
new file mode 100644
index 0000000..9ab0b48
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p6.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class C {
+public:
+ void f(int i = 3); // expected-note{{here}}
+ void g(int i, int j = 99);
+};
+
+void C::f(int i = 3) { } // expected-error{{redefinition of default argument}}
+
+void C::g(int i = 88, int j) { }
+
+void test_C(C c) {
+ c.f();
+ c.g();
+}
+
+template<typename T>
+struct X0 {
+ void f(int);
+
+ struct Inner {
+ void g(int);
+ };
+};
+
+// DR217
+template<typename T>
+void X0<T>::f(int = 17) { } // expected-error{{cannot be added}}
+
+// DR217 + DR205 (reading tea leaves)
+template<typename T>
+void X0<T>::Inner::g(int = 17) { } // expected-error{{cannot be added}}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
new file mode 100644
index 0000000..164eb36
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void h()
+{
+ int i;
+ extern void h2(int x = sizeof(i)); // expected-error {{default argument references local variable 'i' of enclosing function}}
+}
diff --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
new file mode 100644
index 0000000..1a08ab7
--- /dev/null
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+class A {
+ void f(A* p = this) { } // expected-error{{invalid use of 'this'}}
+};