[Sema][NFC] Improve test coverage for builtin operators.

In preparation for D112453.
This commit is contained in:
Clement Courbet 2021-11-03 10:44:21 +01:00
parent 30f922741a
commit 1427742750
10 changed files with 132 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
struct A{};
template <typename T>
void f(int i, float f, bool b, char c, int* pi, A* pa, T* pt) {
(void)+i;
(void)-i;
(void)+f;
(void)-f;
(void)+b;
(void)-b;
(void)+c;
(void)-c;
(void)-pi; // expected-error {{invalid argument type}}
(void)-pa; // expected-error {{invalid argument type}}
(void)-pt; // FIXME: we should be able to give an error here.
}

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
template <typename T>
void f(int i, float f, bool b, char c, int* pi, T* pt) {
(void)~i;
(void)~f; // expected-error {{invalid argument type}}
(void)~b;
(void)~c;
(void)~pi; // expected-error {{invalid argument type}}
(void)~pt; // FIXME: we should be able to give an error here.
}

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
template <typename T>
void f(int i, float f, bool b, char c, int* pi, T* pt) {
(void)!i;
(void)!f;
(void)!b;
(void)!c;
(void)!pi;
(void)!pt;
}
// expected-no-diagnostics

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -std=c++17 -verify %s -Wno-tautological-compare
void f(int i, bool b) {
(void)++i;
(void)i++;
(void)++b; // expected-error {{ISO C++17 does not allow incrementing expression of type bool}}
(void)b++; // expected-error {{ISO C++17 does not allow incrementing expression of type bool}}
}

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
void f(int i, bool b) {
(void)--i;
(void)i--;
(void)--b; // expected-error {{cannot decrement expression of type bool}}
(void)b--; // expected-error {{cannot decrement expression of type bool}}
}

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
struct A{};
template <typename T>
void f(int* pi, A* pa, T* pt) {
(void)++pi;
(void)pi++;
(void)--pi;
(void)pi--;
(void)++pa;
(void)pa++;
(void)--pa;
(void)pa--;
(void)++pt;
(void)pt++;
(void)--pt;
(void)pt--;
}
// expected-no-diagnostics

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++17 -ast-dump %s -ast-dump-filter Test | FileCheck %s
struct A{};
template <typename T>
auto Test(T* pt) {
// CHECK: UnaryOperator {{.*}} '<dependent type>' prefix '*'
// CHECK-NEXT: DeclRefExpr {{.*}} 'T *' lvalue ParmVar {{.*}} 'pt' 'T *'
return *pt;
}

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
struct A{};
template <typename T>
void f(int* pi, A* pa, T* pt) {
(void)*pi;
(void)*pa;
(void)*pt;
}
// expected-no-diagnostics

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
template <typename T>
void f(void(*pf)(), T(*ptf)(T)) {
(void)*pf;
(void)*ptf;
}
// expected-no-diagnostics

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-tautological-compare
struct A{};
template <typename T>
void f(int* pi, A* pa, T* pt) {
(void)+pi;
(void)+pa;
(void)+pt;
}
// expected-no-diagnostics