summaryrefslogtreecommitdiff
path: root/test/FixIt
diff options
context:
space:
mode:
Diffstat (limited to 'test/FixIt')
-rw-r--r--test/FixIt/dereference-addressof.c22
-rw-r--r--test/FixIt/fixit-cxx0x.cpp41
-rw-r--r--test/FixIt/fixit-errors.c2
-rw-r--r--test/FixIt/fixit-function-call.cpp118
-rw-r--r--test/FixIt/fixit-missing-method-return-type.m24
-rw-r--r--test/FixIt/fixit-objc-message.m4
-rw-r--r--test/FixIt/fixit-objc.m14
-rw-r--r--test/FixIt/fixit-static-object-decl.m29
-rw-r--r--test/FixIt/fixit.c15
-rw-r--r--test/FixIt/fixit.cpp13
-rw-r--r--test/FixIt/typo-crash.cpp11
-rw-r--r--test/FixIt/typo.m6
12 files changed, 282 insertions, 17 deletions
diff --git a/test/FixIt/dereference-addressof.c b/test/FixIt/dereference-addressof.c
new file mode 100644
index 0000000000000..950fadc83055c
--- /dev/null
+++ b/test/FixIt/dereference-addressof.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fsyntax-only -fixit -x c %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -x c %t
+
+void ip(int *aPtr) {} // expected-note{{passing argument to parameter 'aPtr' here}}
+void i(int a) {} // expected-note{{passing argument to parameter 'a' here}}
+void ii(int a) {} // expected-note{{passing argument to parameter 'a' here}}
+void fp(float *aPtr) {} // expected-note{{passing argument to parameter 'aPtr' here}}
+void f(float a) {} // expected-note{{passing argument to parameter 'a' here}}
+
+void f2(int *aPtr, int a, float *bPtr, char c) {
+ float fl = 0;
+ ip(a); // expected-warning{{incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'; take the address with &}}
+ i(aPtr); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; dereference with *}}
+ ii(&a); // expected-warning{{incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; remove &}}
+ fp(*bPtr); // expected-error{{passing 'float' to parameter of incompatible type 'float *'; remove *}}
+ f(bPtr); // expected-error{{passing 'float *' to parameter of incompatible type 'float'; dereference with *}}
+ a = aPtr; // expected-warning{{incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *}}
+ fl = bPtr + a; // expected-error{{assigning to 'float' from incompatible type 'float *'; dereference with *}}
+ bPtr = bPtr[a]; // expected-error{{assigning to 'float *' from incompatible type 'float'; take the address with &}}
+}
diff --git a/test/FixIt/fixit-cxx0x.cpp b/test/FixIt/fixit-cxx0x.cpp
index 77e9e5815c2f9..73316457b18f9 100644
--- a/test/FixIt/fixit-cxx0x.cpp
+++ b/test/FixIt/fixit-cxx0x.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify -std=c++0x %s
+// RUN: %clang_cc1 -verify -std=c++11 %s
// RUN: cp %s %t
-// RUN: %clang_cc1 -x c++ -std=c++0x -fixit %t || true
-// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++0x %t
+// RUN: not %clang_cc1 -x c++ -std=c++11 -fixit %t
+// RUN: %clang_cc1 -Wall -pedantic -x c++ -std=c++11 %t
/* This is a test of the various code modification hints that only
apply in C++0x. */
@@ -17,3 +17,38 @@ void x() {
using ::T = void; // expected-error {{name defined in alias declaration must be an identifier}}
using typename U = void; // expected-error {{name defined in alias declaration must be an identifier}}
using typename ::V = void; // expected-error {{name defined in alias declaration must be an identifier}}
+
+namespace Constexpr {
+ extern constexpr int a; // expected-error {{must be a definition}}
+ // -> extern const int a;
+
+ extern constexpr int *b; // expected-error {{must be a definition}}
+ // -> extern int *const b;
+
+ extern constexpr int &c; // expected-error {{must be a definition}}
+ // -> extern int &b;
+
+ extern constexpr const int d; // expected-error {{must be a definition}}
+ // -> extern const int d;
+
+ int z;
+ constexpr int a = 0;
+ constexpr int *b = &z;
+ constexpr int &c = z;
+ constexpr int d = a;
+
+ // FIXME: Provide FixIts for static data members too.
+#if 0
+ struct S {
+ static constexpr int b; // xpected-error {{requires an initializer}}
+ // -> const int b;
+ };
+
+ constexpr int S::b = 0;
+#endif
+
+ struct S {
+ static char *const p = 0; // expected-error {{requires 'constexpr' specifier}}
+ // -> constexpr static char *const p = 0;
+ };
+}
diff --git a/test/FixIt/fixit-errors.c b/test/FixIt/fixit-errors.c
index f8e2295d496ad..356e862ff6069 100644
--- a/test/FixIt/fixit-errors.c
+++ b/test/FixIt/fixit-errors.c
@@ -1,5 +1,5 @@
// RUN: cp %s %t
-// RUN: true || %clang_cc1 -pedantic -verify -fixit -x c %t
+// RUN: %clang_cc1 -pedantic -verify -fixit -x c %t
// RUN: %clang_cc1 -pedantic -Werror -x c %t
// XFAIL: *
diff --git a/test/FixIt/fixit-function-call.cpp b/test/FixIt/fixit-function-call.cpp
new file mode 100644
index 0000000000000..273e4a41ec8dd
--- /dev/null
+++ b/test/FixIt/fixit-function-call.cpp
@@ -0,0 +1,118 @@
+// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -x c++ %s 2> %t
+// RUN: FileCheck %s < %t
+// PR5941
+// END.
+
+/* Test fixits for * and & mismatch in function arguments.
+ * Since fixits are on the notes, they cannot be applied automatically. */
+
+typedef int intTy;
+typedef int intTy2;
+
+void f0(int *a);
+void f1(double *a);
+void f1(intTy &a);
+
+void f2(intTy2 *a) {
+// CHECK: error: no matching function for call to 'f1
+// CHECK: dereference the argument with *
+// CHECK: void f1(intTy &a);
+// CHECK: fix-it{{.*}}*(
+// CHECK-NEXT: fix-it{{.*}})
+// CHECK: void f1(double *a);
+ f1(a + 1);
+
+// This call cannot be fixed since without resulting in null pointer dereference.
+// CHECK: error: no matching function for call to 'f1
+// CHECK-NOT: dereference the argument with *
+// CHECK-NOT: fix-it
+ f1((int *)0);
+}
+
+void f3(int &a) {
+// CHECK: error: no matching function for call to 'f0
+// CHECK: fix-it{{.*}}&
+ f0(a);
+}
+
+
+void m(int *a, const int *b); // match 2
+void m(double *a, int *b); // no match
+void m(int *a, double *b); // no match
+void m(intTy &a, int *b); // match 1
+
+void mcaller(intTy2 a, int b) {
+// CHECK: error: no matching function for call to 'm
+// CHECK: take the address of the argument with &
+// CHECK: fix-it{{.*}}&
+// CHECK: take the address of the argument with &
+// CHECK: fix-it{{.*}}&
+// CHECK: fix-it{{.*}}&
+ m(a, b);
+
+// This call cannot be fixed because (a + 1) is not an l-value.
+// CHECK: error: no matching function for call to 'm
+// CHECK-NOT: fix-it
+ m(a + 1, b);
+}
+
+// Test derived to base conversions.
+struct A {
+ int xx;
+};
+
+struct B : public A {
+ double y;
+};
+
+class C : A {};
+
+bool br(A &a);
+bool bp(A *a);
+bool dv(B b);
+
+void u(int x);
+void u(const C *x);
+void u(double x);
+
+void dbcaller(A *ptra, B *ptrb, C &c, B &refb) {
+ B b;
+
+// CHECK: error: no matching function for call to 'br
+// CHECK: fix-it{{.*}}*
+ br(ptrb); // good
+
+// CHECK: error: no matching function for call to 'bp
+// CHECK: fix-it{{.*}}&
+ bp(b); // good
+
+// CHECK: error: no matching function for call to 'dv
+// CHECK-NOT: fix-it
+ dv(ptra); // bad: base to derived
+
+// CHECK: error: no matching function for call to 'dv
+// CHECK: remove &
+ dv(&b);
+
+// CHECK: error: no matching function for call to 'bp
+// CHECK: remove *
+ bp(*ptra);
+
+// CHECK: error: no viable overloaded '='
+// CHECK: remove &
+ b = &refb;
+
+// TODO: Test that we do not provide a fixit when inheritance is private.
+// CHECK: error: no matching function for call to 'bp
+// There should not be a fixit here:
+// CHECK: fix-it
+ bp(c);
+
+// CHECK: no matching function for call to 'u'
+// CHECK: candidate function not viable: no known conversion from 'C' to 'const C *' for 1st argument; take the address of the argument with &
+// CHECK: candidate function not viable
+// CHECK: candidate function not viable
+ u(c);
+}
+
+// CHECK: errors generated
diff --git a/test/FixIt/fixit-missing-method-return-type.m b/test/FixIt/fixit-missing-method-return-type.m
new file mode 100644
index 0000000000000..027c89572ff96
--- /dev/null
+++ b/test/FixIt/fixit-missing-method-return-type.m
@@ -0,0 +1,24 @@
+// Objective-C recovery
+// RUN: cp %s %t
+// RUN: %clang_cc1 -Wmissing-method-return-type -fixit -x objective-c %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Wmissing-method-return-type -Werror -x objective-c %t
+
+// Objective-C++ recovery
+// RUN: cp %s %t
+// RUN: %clang_cc1 -Wmissing-method-return-type -fixit -x objective-c++ %t
+// RUN: %clang_cc1 -fsyntax-only -pedantic -Wmissing-method-return-type -Werror -x objective-c++ %t
+// rdar://9615045
+
+@interface I
+- initWithFoo:(id)foo; // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}}
+- Meth;
+-Meth1;
+@end
+
+@implementation I
+- initWithFoo:(id)foo { return 0; } // expected-warning {{method has no return type specified; defaults to 'id' [-Wmissing-method-return-type]}}
+
+-Meth { return 0;}
+- Meth1 { return 0;}
+@end
+
diff --git a/test/FixIt/fixit-objc-message.m b/test/FixIt/fixit-objc-message.m
index 1fef3cc56d5ed..a3680e475ee2e 100644
--- a/test/FixIt/fixit-objc-message.m
+++ b/test/FixIt/fixit-objc-message.m
@@ -1,11 +1,11 @@
// Objective-C recovery
// RUN: cp %s %t
-// RUN: %clang_cc1 -pedantic -Wall -fixit -x objective-c %t || true
+// RUN: not %clang_cc1 -pedantic -Wall -fixit -x objective-c %t
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x objective-c %t
// Objective-C++ recovery
// RUN: cp %s %t
-// RUN: %clang_cc1 -pedantic -Wall -fixit -x objective-c++ %t || true
+// RUN: not %clang_cc1 -pedantic -Wall -fixit -x objective-c++ %t
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x objective-c++ %t
@interface A
diff --git a/test/FixIt/fixit-objc.m b/test/FixIt/fixit-objc.m
index 2e8bfaea6aa3a..df591c7922964 100644
--- a/test/FixIt/fixit-objc.m
+++ b/test/FixIt/fixit-objc.m
@@ -53,3 +53,17 @@ int f0(Radar7861841 *a) { return a.x; } // expected-error {{property 'x' not fou
int f1(Radar7861841 *a) { return a->y; } // expected-error {{property 'y' found on object of type 'Radar7861841 *'; did you mean to access it with the "." operator?}}
+
+#define nil ((void*)0)
+#define NULL ((void*)0)
+
+void sentinel(int x, ...) __attribute__((sentinel)); // expected-note{{function has been explicitly marked sentinel here}}
+
+@interface Sentinel
+- (void)sentinel:(int)x, ... __attribute__((sentinel)); // expected-note{{method has been explicitly marked sentinel here}}
+@end
+
+void sentinel_test(Sentinel *a) {
+ sentinel(1, 2, 3); // expected-warning{{missing sentinel in function call}}
+ [a sentinel:1, 2, 3]; // expected-warning{{missing sentinel in method dispatch}}
+}
diff --git a/test/FixIt/fixit-static-object-decl.m b/test/FixIt/fixit-static-object-decl.m
new file mode 100644
index 0000000000000..e13900fa786f4
--- /dev/null
+++ b/test/FixIt/fixit-static-object-decl.m
@@ -0,0 +1,29 @@
+// Objective-C recovery
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fixit -x objective-c %t
+// RUN: %clang_cc1 -fsyntax-only -Werror -x objective-c %t
+
+// Objective-C++ recovery
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fixit -x objective-c++ %t
+// RUN: %clang_cc1 -fsyntax-only -Werror -x objective-c++ %t
+// rdar://9603056
+
+@interface S @end
+
+@interface NSArray
+{
+@public
+ S iS;
+}
++ (id) arrayWithObjects;
+@end
+
+NSArray func() {
+ NSArray P;
+ return P;
+}
+
+int main() {
+ NSArray pluginNames = [NSArray arrayWithObjects];
+}
diff --git a/test/FixIt/fixit.c b/test/FixIt/fixit.c
index ba45cf28e6948..5ba0aac4509b6 100644
--- a/test/FixIt/fixit.c
+++ b/test/FixIt/fixit.c
@@ -1,7 +1,7 @@
// RUN: cp %s %t
-// RUN: %clang_cc1 -pedantic -fixit -x c %t || true
+// RUN: not %clang_cc1 -pedantic -Wunused-label -fixit -x c %t
// RUN: grep -v CHECK %t > %t2
-// RUN: %clang_cc1 -pedantic -Werror -x c %t
+// RUN: %clang_cc1 -pedantic -Wunused-label -Werror -x c %t
// RUN: FileCheck -input-file=%t2 %t
/* This is a test of the various code modification hints that are
@@ -59,3 +59,14 @@ struct test_struct {
// CHECK: struct test_struct *struct_ptr;
test_struct *struct_ptr; // expected-error {{must use 'struct' tag to refer to type 'test_struct'}}
};
+
+void removeUnusedLabels(char c) {
+ L0 /*removed comment*/: c++;
+ removeUnusedLabels(c);
+ L1:
+ c++;
+ /*preserved comment*/ L2 : c++;
+ LL
+ : c++;
+ c = c + 3; L4: return;
+}
diff --git a/test/FixIt/fixit.cpp b/test/FixIt/fixit.cpp
index ac749859ea052..785b92b2d8179 100644
--- a/test/FixIt/fixit.cpp
+++ b/test/FixIt/fixit.cpp
@@ -1,5 +1,5 @@
// RUN: cp %s %t
-// RUN: %clang_cc1 -pedantic -Wall -fixit -x c++ %t || true
+// RUN: not %clang_cc1 -pedantic -Wall -fixit -x c++ %t
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror -x c++ %t
/* This is a test of the various code modification hints that are
@@ -96,4 +96,15 @@ void f(){
typename F1<T>:: /*template*/ Iterator<0> Mypos; // expected-error {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
}
+// Tests for &/* fixits radar 7113438.
+class AD {};
+class BD: public AD {};
+
+void test (BD &br) {
+ AD* aPtr;
+ BD b;
+ aPtr = b; // expected-error {{assigning to 'AD *' from incompatible type 'BD'; take the address with &}}
+ aPtr = br; // expected-error {{assigning to 'A *' from incompatible type 'B'; take the address with &}}
+}
+
diff --git a/test/FixIt/typo-crash.cpp b/test/FixIt/typo-crash.cpp
index b156e1b44c45f..92d20377e8868 100644
--- a/test/FixIt/typo-crash.cpp
+++ b/test/FixIt/typo-crash.cpp
@@ -3,9 +3,10 @@
// FIXME: The diagnostics and recovery here are very, very poor.
// PR10355
-template<typename T> void template_id1() {
- template_id2<> t; // expected-error 2{{use of undeclared identifier 'template_id2'; did you mean 'template_id1'?}} \
- // expected-error{{expected expression}} \
- // expected-error{{use of undeclared identifier 't'}}
+template<typename T> void template_id1() { // expected-note {{'template_id1' declared here}} \
+ // expected-note {{possible target for call}}
+ template_id2<> t; // expected-error {{no template named 'template_id2'; did you mean 'template_id1'?}} \
+ // expected-error {{expected ';' after expression}} \
+ // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} \
+ // expected-error {{use of undeclared identifier 't'}}
}
-
diff --git a/test/FixIt/typo.m b/test/FixIt/typo.m
index ecb207ee3917b..a474035021e6d 100644
--- a/test/FixIt/typo.m
+++ b/test/FixIt/typo.m
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -DNON_FIXITS -verify %s
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-darwin10 -DNON_FIXITS -verify %s
// RUN: cp %s %t
-// RUN: not %clang_cc1 -x objective-c -fsyntax-only -fobjc-nonfragile-abi -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t
-// RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-nonfragile-abi -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -pedantic -Werror %t
+// RUN: not %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fixit %t
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -pedantic -Werror %t
// RUN: grep "@implementation Sub3" %t
@interface NSString // expected-note 2{{'NSString' declared here}}