diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2012-12-02 13:20:44 +0000 |
commit | 13cc256e404620c1de0cbcc4e43ce1e2dbbc4898 (patch) | |
tree | 2732d02d7d51218d6eed98ac7fcfc5b8794896b5 /test/SemaCXX | |
parent | 657bc3d9848e3be92029b2416031340988cd0111 (diff) |
Notes
Diffstat (limited to 'test/SemaCXX')
141 files changed, 2378 insertions, 300 deletions
diff --git a/test/SemaCXX/2008-01-11-BadWarning.cpp b/test/SemaCXX/2008-01-11-BadWarning.cpp index b84e7c1cf862d..e27c0848ef37e 100644 --- a/test/SemaCXX/2008-01-11-BadWarning.cpp +++ b/test/SemaCXX/2008-01-11-BadWarning.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s +// expected-no-diagnostics // rdar://5683899 void** f(void **Buckets, unsigned NumBuckets) { return Buckets + NumBuckets; diff --git a/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp b/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp index d932b5dbbceaa..14e5160e090b0 100644 --- a/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp +++ b/test/SemaCXX/MicrosoftCompatibilityNoExceptions.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility +// expected-no-diagnostics // PR13153 namespace std {} diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 0b72cd3e1fc0d..6b43ea205af3f 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions // ::type_info is predeclared with forward class declartion @@ -112,11 +112,11 @@ const int seventeen = 17; typedef int Int; struct X0 { - enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} + enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} enum E1 : seventeen; }; -enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} +enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} SomeValue = 0x100000000 }; @@ -203,3 +203,4 @@ struct PR11150 { void f() { int __except = 0; } +void ::f(); // expected-warning{{extra qualification on member 'f'}} diff --git a/test/SemaCXX/PR10447.cpp b/test/SemaCXX/PR10447.cpp index 08644ada4a4b9..5ba74aaba36c2 100644 --- a/test/SemaCXX/PR10447.cpp +++ b/test/SemaCXX/PR10447.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify %s +// expected-no-diagnostics // PR12223 namespace test1 { diff --git a/test/SemaCXX/PR5086-ambig-resolution-enum.cpp b/test/SemaCXX/PR5086-ambig-resolution-enum.cpp index b5aac5f09c16a..eeb73f6f56c92 100644 --- a/test/SemaCXX/PR5086-ambig-resolution-enum.cpp +++ b/test/SemaCXX/PR5086-ambig-resolution-enum.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics class C { public: diff --git a/test/SemaCXX/PR6562.cpp b/test/SemaCXX/PR6562.cpp index 854d9b058bc3d..144fde68b1786 100644 --- a/test/SemaCXX/PR6562.cpp +++ b/test/SemaCXX/PR6562.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics struct X { ~X(); }; template <typename T> diff --git a/test/SemaCXX/PR9884.cpp b/test/SemaCXX/PR9884.cpp index ab883c4062c90..bb8bd6a56bff9 100644 --- a/test/SemaCXX/PR9884.cpp +++ b/test/SemaCXX/PR9884.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics class Base { protected: Base(int val); diff --git a/test/SemaCXX/PR9902.cpp b/test/SemaCXX/PR9902.cpp index 80086e445c5dc..a34f99c12287b 100644 --- a/test/SemaCXX/PR9902.cpp +++ b/test/SemaCXX/PR9902.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// expected-no-diagnostics template <class _Tp, class _Up, bool = false> struct __allocator_traits_rebind diff --git a/test/SemaCXX/PR9908.cpp b/test/SemaCXX/PR9908.cpp index fc090cc42f928..a15b637a03d29 100644 --- a/test/SemaCXX/PR9908.cpp +++ b/test/SemaCXX/PR9908.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// expected-no-diagnostics template <class _Tp, class _Up> struct __allocator_traits_rebind diff --git a/test/SemaCXX/__try.cpp b/test/SemaCXX/__try.cpp index cb5d38a097ef2..a0f503abe6c8f 100644 --- a/test/SemaCXX/__try.cpp +++ b/test/SemaCXX/__try.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s +// expected-no-diagnostics // This test is from http://docwiki.embarcadero.com/RADStudio/en/Try diff --git a/test/SemaCXX/ambiguous-conversion-show-overload.cpp b/test/SemaCXX/ambiguous-conversion-show-overload.cpp new file mode 100644 index 0000000000000..64296512ffd7b --- /dev/null +++ b/test/SemaCXX/ambiguous-conversion-show-overload.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -fno-caret-diagnostics %s 2>&1 | FileCheck %s +struct S { + S(void*); + S(char*); + S(unsigned char*); + S(signed char*); + S(unsigned short*); + S(signed short*); + S(unsigned int*); + S(signed int*); +}; +void f(const S& s); +void g() { + f(0); +} +// CHECK: {{conversion from 'int' to 'const S' is ambiguous}} +// CHECK-NEXT: {{candidate constructor}} +// CHECK-NEXT: {{candidate constructor}} +// CHECK-NEXT: {{candidate constructor}} +// CHECK-NEXT: {{candidate constructor}} +// CHECK-NEXT: {{remaining 4 candidates omitted; pass -fshow-overloads=all to show them}} diff --git a/test/SemaCXX/anonymous-union-cxx11.cpp b/test/SemaCXX/anonymous-union-cxx11.cpp index 8e682ebcda3d1..9f987a9681cdd 100644 --- a/test/SemaCXX/anonymous-union-cxx11.cpp +++ b/test/SemaCXX/anonymous-union-cxx11.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s +// expected-no-diagnostics namespace PR12866 { struct bar { diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp new file mode 100644 index 0000000000000..aeb4039d597d0 --- /dev/null +++ b/test/SemaCXX/ast-print.cpp @@ -0,0 +1,83 @@ +// RUN: %clang_cc1 -ast-print %s | FileCheck %s + +// CHECK: r; +// CHECK-NEXT: (r->method()); +struct MyClass +{ + void method() {} +}; + +struct Reference +{ + MyClass* object; + MyClass* operator ->() { return object; } +}; + +void test1() { + Reference r; + (r->method()); +} + +// CHECK: if (int a = 1) +// CHECK: while (int a = 1) +// CHECK: switch (int a = 1) + +void test2() +{ + if (int a = 1) { } + while (int a = 1) { } + switch (int a = 1) { } +} + +// CHECK: new (1) int; +void *operator new (typeof(sizeof(1)), int, int = 2); +void test3() { + new (1) int; +} + +// CHECK: new X; +struct X { + void *operator new (typeof(sizeof(1)), int = 2); +}; +void test4() { new X; } + +// CHECK: for (int i = 2097, j = 42; false;) +void test5() { + for (int i = 2097, j = 42; false;) {} +} + +// CHECK: test6fn((int &)y); +void test6fn(int& x); +void test6() { + unsigned int y = 0; + test6fn((int&)y); +} + +// CHECK: S s( 1, 2 ); + +template <class S> void test7() +{ + S s( 1,2 ); +} + + +// CHECK: t.~T(); + +template <typename T> void test8(T t) { t.~T(); } + + +// CHECK: enum E { +// CHECK-NEXT: A, +// CHECK-NEXT: B, +// CHECK-NEXT: C +// CHECK-NEXT: }; +// CHECK-NEXT: {{^[ ]+}}E a = A; + +struct test9 +{ + void f() + { + enum E { A, B, C }; + E a = A; + } +}; diff --git a/test/SemaCXX/attr-format.cpp b/test/SemaCXX/attr-format.cpp index da134a136d26d..3d5c3391c2634 100644 --- a/test/SemaCXX/attr-format.cpp +++ b/test/SemaCXX/attr-format.cpp @@ -14,6 +14,8 @@ struct S { expected-error{{out of bounds}} const char* h3(const char*) __attribute__((format_arg(1))); // \ expected-error{{invalid for the implicit this argument}} + + void operator() (const char*, ...) __attribute__((format(printf, 2, 3))); }; // PR5521 @@ -33,3 +35,9 @@ namespace PR8625 { s.f(str, "%s", str); } } + +// Make sure we interpret member operator calls as having an implicit +// this argument. +void test_operator_call(S s, const char* str) { + s("%s", str); +} diff --git a/test/SemaCXX/attr-nodebug.cpp b/test/SemaCXX/attr-nodebug.cpp new file mode 100644 index 0000000000000..b441da21f8e7a --- /dev/null +++ b/test/SemaCXX/attr-nodebug.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only +// Note: most of the 'nodebug' tests are in attr-nodebug.c. + +// expected-no-diagnostics +class c { + void t3() __attribute__((nodebug)); +}; diff --git a/test/SemaCXX/attr-noreturn.cpp b/test/SemaCXX/attr-noreturn.cpp index eaf0d0c15ffd1..f3d548b793b05 100644 --- a/test/SemaCXX/attr-noreturn.cpp +++ b/test/SemaCXX/attr-noreturn.cpp @@ -54,3 +54,29 @@ class xpto { int xpto::blah() { return 3; // expected-warning {{function 'blah' declared 'noreturn' should not return}} } + +// PR12948 + +namespace PR12948 { + template<int> + void foo() __attribute__((__noreturn__)); + + template<int> + void foo() { + while (1) continue; + } + + void bar() __attribute__((__noreturn__)); + + void bar() { + foo<0>(); + } + + + void baz() __attribute__((__noreturn__)); + typedef void voidfn(); + voidfn baz; + + template<typename> void wibble() __attribute__((__noreturn__)); + template<typename> voidfn wibble; +} diff --git a/test/SemaCXX/attr-unused.cpp b/test/SemaCXX/attr-unused.cpp new file mode 100644 index 0000000000000..b74bc915ce070 --- /dev/null +++ b/test/SemaCXX/attr-unused.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify -Wunused -Wused-but-marked-unused -fsyntax-only %s + +namespace ns_unused { typedef int Int_unused __attribute__((unused)); } +namespace ns_not_unused { typedef int Int_not_unused; } + +void f() { + ns_not_unused::Int_not_unused i1; // expected-warning {{unused variable}} + ns_unused::Int_unused i0; // expected-warning {{'Int_unused' was marked unused but was used}} +} diff --git a/test/SemaCXX/blocks-1.cpp b/test/SemaCXX/blocks-1.cpp index 1b1509482af35..02e9cac62ebec 100644 --- a/test/SemaCXX/blocks-1.cpp +++ b/test/SemaCXX/blocks-1.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks -std=c++11 +// expected-no-diagnostics extern "C" int exit(int); diff --git a/test/SemaCXX/blocks.cpp b/test/SemaCXX/blocks.cpp index adbff553e6086..3f81c274d04f8 100644 --- a/test/SemaCXX/blocks.cpp +++ b/test/SemaCXX/blocks.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks +// expected-no-diagnostics void tovoid(void*); diff --git a/test/SemaCXX/borland-extensions.cpp b/test/SemaCXX/borland-extensions.cpp index 483153004dcba..1e4bd45612fd8 100644 --- a/test/SemaCXX/borland-extensions.cpp +++ b/test/SemaCXX/borland-extensions.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -fborland-extensions +// expected-no-diagnostics // Borland extensions diff --git a/test/SemaCXX/builtin-exception-spec.cpp b/test/SemaCXX/builtin-exception-spec.cpp index 324d20ea6a159..590cd3c35d4e1 100644 --- a/test/SemaCXX/builtin-exception-spec.cpp +++ b/test/SemaCXX/builtin-exception-spec.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -isystem %S/Inputs -fsyntax-only -verify %s +// expected-no-diagnostics #include <malloc.h> extern "C" { diff --git a/test/SemaCXX/builtin-ptrtomember-overload.cpp b/test/SemaCXX/builtin-ptrtomember-overload.cpp index c7b5173a4fbe9..c27d642f9a46b 100644 --- a/test/SemaCXX/builtin-ptrtomember-overload.cpp +++ b/test/SemaCXX/builtin-ptrtomember-overload.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics struct A {}; diff --git a/test/SemaCXX/builtin_objc_msgSend.cpp b/test/SemaCXX/builtin_objc_msgSend.cpp index 0e90d54f804fa..082fb2868c639 100644 --- a/test/SemaCXX/builtin_objc_msgSend.cpp +++ b/test/SemaCXX/builtin_objc_msgSend.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify +// expected-no-diagnostics // rdar://8686888 typedef struct objc_selector *SEL; diff --git a/test/SemaCXX/builtins-arm.cpp b/test/SemaCXX/builtins-arm.cpp new file mode 100644 index 0000000000000..8a0cf8102b35e --- /dev/null +++ b/test/SemaCXX/builtins-arm.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify %s + +// va_list on ARM AAPCS is struct { void* __ap }. +int test1(const __builtin_va_list &ap) { + return __builtin_va_arg(ap, int); // expected-error {{binding of reference to type '__builtin_va_list' to a value of type 'const __builtin_va_list' drops qualifiers}} +} diff --git a/test/SemaCXX/builtins-va_arg.cpp b/test/SemaCXX/builtins-va_arg.cpp new file mode 100644 index 0000000000000..4f549c8db6f0d --- /dev/null +++ b/test/SemaCXX/builtins-va_arg.cpp @@ -0,0 +1,52 @@ +// RUN: %clang_cc1 %s -ffreestanding +// RUN: %clang_cc1 %s -ffreestanding -triple i686-unknown-linux +// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-linux +// RUN: %clang_cc1 %s -ffreestanding -triple mips-unknown-linux +// RUN: %clang_cc1 %s -ffreestanding -triple mipsel-unknown-linux +// RUN: %clang_cc1 %s -ffreestanding -triple armv7-unknown-linux-gnueabi +// RUN: %clang_cc1 %s -ffreestanding -triple thumbv7-unknown-linux-gnueabi + +#include "stdarg.h" + +int int_accumulator = 0; +double double_accumulator = 0; + +int test_vprintf(const char *fmt, va_list ap) { + char ch; + int result = 0; + while (*fmt != '\0') { + ch = *fmt++; + if (ch != '%') { + continue; + } + + ch = *fmt++; + switch (ch) { + case 'd': + int_accumulator += va_arg(ap, int); + result++; + break; + + case 'f': + double_accumulator += va_arg(ap, double); + result++; + break; + + default: + break; + } + + if (ch == '0') { + break; + } + } + return result; +} + +int test_printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int result = test_vprintf(fmt, ap); + va_end(ap); + return result; +} diff --git a/test/SemaCXX/builtins.cpp b/test/SemaCXX/builtins.cpp index 568ba5dde1295..6b055cff640d7 100644 --- a/test/SemaCXX/builtins.cpp +++ b/test/SemaCXX/builtins.cpp @@ -7,3 +7,16 @@ void f() { } void a() { __builtin_va_list x, y; ::__builtin_va_copy(x, y); } + +// <rdar://problem/10063539> +template<int (*Compare)(const char *s1, const char *s2)> +int equal(const char *s1, const char *s2) { + return Compare(s1, s2) == 0; +} +// FIXME: Our error recovery here sucks +template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}} expected-error {{expected unqualified-id}} expected-error {{expected ')'}} expected-note {{to match this '('}} + +// PR13195 +void f2() { + __builtin_isnan; // expected-error {{builtin functions must be directly called}} +} diff --git a/test/SemaCXX/cast-conversion.cpp b/test/SemaCXX/cast-conversion.cpp index dd2bc98e02cc7..270f96831bd4e 100644 --- a/test/SemaCXX/cast-conversion.cpp +++ b/test/SemaCXX/cast-conversion.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11 struct R { R(int); @@ -45,3 +45,23 @@ protected: static_cast<float*>(f0<0>()); // expected-error{{ambiguous}} } }; + +void *intToPointer1(short s) { + return (void*)s; // expected-warning{{cast to 'void *' from smaller integer type 'short'}} +} + +void *intToPointer2(short s) { + return reinterpret_cast<void*>(s); +} + +void *intToPointer3(bool b) { + return (void*)b; +} + +void *intToPointer4() { + return (void*)(3 + 7); +} + +void *intToPointer5(long l) { + return (void*)l; +} diff --git a/test/SemaCXX/cast-explicit-ctor.cpp b/test/SemaCXX/cast-explicit-ctor.cpp index 0052856d2ff92..41d2fa2fbf2c7 100644 --- a/test/SemaCXX/cast-explicit-ctor.cpp +++ b/test/SemaCXX/cast-explicit-ctor.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics struct B { explicit B(bool); }; void f() { (void)(B)true; diff --git a/test/SemaCXX/class-layout.cpp b/test/SemaCXX/class-layout.cpp index d81944ab9b3ca..f2ff9fcfd7c19 100644 --- a/test/SemaCXX/class-layout.cpp +++ b/test/SemaCXX/class-layout.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify +// expected-no-diagnostics #define SA(n, p) int a##n[(p) ? 1 : -1] diff --git a/test/SemaCXX/class.cpp b/test/SemaCXX/class.cpp index 4dffc8d9ecb80..972a79bb60900 100644 --- a/test/SemaCXX/class.cpp +++ b/test/SemaCXX/class.cpp @@ -120,7 +120,7 @@ struct C4 { struct S { void f(); // expected-note 1 {{previous declaration}} - void S::f() {} // expected-warning {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} + void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}} }; diff --git a/test/SemaCXX/comma.cpp b/test/SemaCXX/comma.cpp index 79ff7d1cde251..3a6162bc473e2 100644 --- a/test/SemaCXX/comma.cpp +++ b/test/SemaCXX/comma.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics // PR6076 void f(); diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp index 28e2dd0ad51a6..432069f60cc01 100644 --- a/test/SemaCXX/compare.cpp +++ b/test/SemaCXX/compare.cpp @@ -89,8 +89,8 @@ int test0(long a, unsigned long b) { // (C,b) (C == (unsigned long) b) + (C == (unsigned int) b) + - (C == (unsigned short) b) + - (C == (unsigned char) b) + + (C == (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}} + (C == (unsigned char) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}} ((long) C == b) + ((int) C == b) + ((short) C == b) + @@ -101,8 +101,8 @@ int test0(long a, unsigned long b) { ((signed char) C == (unsigned char) b) + (C < (unsigned long) b) + (C < (unsigned int) b) + - (C < (unsigned short) b) + - (C < (unsigned char) b) + + (C < (unsigned short) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned short' is always false}} + (C < (unsigned char) b) + // expected-warning {{comparison of constant 65536 with expression of type 'unsigned char' is always false}} ((long) C < b) + ((int) C < b) + ((short) C < b) + @@ -119,8 +119,8 @@ int test0(long a, unsigned long b) { (a == (unsigned char) C) + ((long) a == C) + ((int) a == C) + - ((short) a == C) + - ((signed char) a == C) + + ((short) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always false}} + ((signed char) a == C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) C) + ((int) a == (unsigned int) C) + ((short) a == (unsigned short) C) + @@ -131,8 +131,8 @@ int test0(long a, unsigned long b) { (a < (unsigned char) C) + ((long) a < C) + ((int) a < C) + - ((short) a < C) + - ((signed char) a < C) + + ((short) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'short' is always true}} + ((signed char) a < C) + // expected-warning {{comparison of constant 65536 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) C) + @@ -141,8 +141,8 @@ int test0(long a, unsigned long b) { // (0x80000,b) (0x80000 == (unsigned long) b) + (0x80000 == (unsigned int) b) + - (0x80000 == (unsigned short) b) + - (0x80000 == (unsigned char) b) + + (0x80000 == (unsigned short) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned short' is always false}} + (0x80000 == (unsigned char) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 == b) + ((int) 0x80000 == b) + ((short) 0x80000 == b) + @@ -153,8 +153,8 @@ int test0(long a, unsigned long b) { ((signed char) 0x80000 == (unsigned char) b) + (0x80000 < (unsigned long) b) + (0x80000 < (unsigned int) b) + - (0x80000 < (unsigned short) b) + - (0x80000 < (unsigned char) b) + + (0x80000 < (unsigned short) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned short' is always false}} + (0x80000 < (unsigned char) b) + // expected-warning {{comparison of constant 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 < b) + ((int) 0x80000 < b) + ((short) 0x80000 < b) + @@ -171,8 +171,8 @@ int test0(long a, unsigned long b) { (a == (unsigned char) 0x80000) + ((long) a == 0x80000) + ((int) a == 0x80000) + - ((short) a == 0x80000) + - ((signed char) a == 0x80000) + + ((short) a == 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'short' is always false}} + ((signed char) a == 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) 0x80000) + ((int) a == (unsigned int) 0x80000) + ((short) a == (unsigned short) 0x80000) + @@ -183,8 +183,8 @@ int test0(long a, unsigned long b) { (a < (unsigned char) 0x80000) + ((long) a < 0x80000) + ((int) a < 0x80000) + - ((short) a < 0x80000) + - ((signed char) a < 0x80000) + + ((short) a < 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'short' is always true}} + ((signed char) a < 0x80000) + // expected-warning {{comparison of constant 524288 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) 0x80000) + diff --git a/test/SemaCXX/complex-init-list.cpp b/test/SemaCXX/complex-init-list.cpp index e75833a37dbc5..f70f9df6c73b9 100644 --- a/test/SemaCXX/complex-init-list.cpp +++ b/test/SemaCXX/complex-init-list.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic +// expected-no-diagnostics // This file tests the clang extension which allows initializing the components // of a complex number individually using an initialization list. Basically, diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index a80eda416f4eb..7595f1dfa1c00 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -57,6 +57,16 @@ struct Ambig { operator signed char(); // expected-note 2 {{candidate function}} }; +struct Abstract { + virtual ~Abstract() = 0; // expected-note {{unimplemented pure virtual method '~Abstract' in 'Abstract'}} +}; + +struct Derived1: Abstract { +}; + +struct Derived2: Abstract { +}; + void test() { // This function tests C++0x 5.16 @@ -206,6 +216,9 @@ void test() // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. + + const Abstract &a = true ? static_cast<const Abstract&>(Derived1()) : Derived2(); // expected-error {{allocating an object of abstract class type 'const Abstract'}} + true ? static_cast<const Abstract&>(Derived1()) : throw 3; // expected-error {{allocating an object of abstract class type 'const Abstract'}} } namespace PR6595 { diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index a3ead79a84568..f504eb621f6c2 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -521,12 +521,18 @@ namespace DependentValues { struct I { int n; typedef I V[10]; }; I::V x, y; -template<bool B> struct S { +int g(); +template<bool B, typename T> struct S : T { int k; void f() { I::V &cells = B ? x : y; I &i = cells[k]; switch (i.n) {} + + // FIXME: We should be able to diagnose this. + constexpr int n = g(); + + constexpr int m = this->g(); // ok, could be constexpr } }; @@ -741,6 +747,15 @@ constexpr bool check(T a, T b) { return a == b.k; } static_assert(S(5) == 11, ""); static_assert(check(S(5), 11), ""); +namespace PR14171 { + +struct X { + constexpr (operator int)() { return 0; } +}; +static_assert(X() == 0, ""); + +} + } } @@ -1374,3 +1389,69 @@ namespace ConditionalLValToRVal { constexpr A a(4); static_assert(f(a).v == 4, ""); } + +namespace TLS { + __thread int n; + int m; + + constexpr bool b = &n == &n; + + constexpr int *p = &n; // expected-error{{constexpr variable 'p' must be initialized by a constant expression}} + + constexpr int *f() { return &n; } + constexpr int *q = f(); // expected-error{{constexpr variable 'q' must be initialized by a constant expression}} + constexpr bool c = f() == f(); + + constexpr int *g() { return &m; } + constexpr int *r = g(); +} + +namespace Void { + constexpr void f() { return; } // expected-error{{constexpr function's return type 'void' is not a literal type}} + + void assert_failed(const char *msg, const char *file, int line); // expected-note {{declared here}} +#define ASSERT(expr) ((expr) ? static_cast<void>(0) : assert_failed(#expr, __FILE__, __LINE__)) + template<typename T, size_t S> + constexpr T get(T (&a)[S], size_t k) { + return ASSERT(k > 0 && k < S), a[k]; // expected-note{{non-constexpr function 'assert_failed'}} + } +#undef ASSERT + template int get(int (&a)[4], size_t); + constexpr int arr[] = { 4, 1, 2, 3, 4 }; + static_assert(get(arr, 1) == 1, ""); + static_assert(get(arr, 4) == 4, ""); + static_assert(get(arr, 0) == 4, ""); // expected-error{{not an integral constant expression}} \ + // expected-note{{in call to 'get(arr, 0)'}} +} + +namespace std { struct type_info; } + +namespace TypeId { + struct A { virtual ~A(); }; + A f(); + A &g(); + constexpr auto &x = typeid(f()); + constexpr auto &y = typeid(g()); // expected-error{{constant expression}} \ + // expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} +} + +namespace PR14203 { + struct duration { + constexpr duration() {} + constexpr operator int() const { return 0; } + }; + template<typename T> void f() { + // If we want to evaluate this at the point of the template definition, we + // need to trigger the implicit definition of the move constructor at that + // point. + // FIXME: C++ does not permit us to implicitly define it at the appropriate + // times, since it is only allowed to be implicitly defined when it is + // odr-used. + constexpr duration d = duration(); + } + // FIXME: It's unclear whether this is valid. On the one hand, we're not + // allowed to generate a move constructor. On the other hand, if we did, + // this would be a constant expression. For now, we generate a move + // constructor here. + int n = sizeof(short{duration(duration())}); +} diff --git a/test/SemaCXX/constant-expression.cpp b/test/SemaCXX/constant-expression.cpp index ec50cb7d92fcd..942bf414742b2 100644 --- a/test/SemaCXX/constant-expression.cpp +++ b/test/SemaCXX/constant-expression.cpp @@ -115,7 +115,7 @@ int array2[recurse2]; // expected-warning {{variable length array}} expected-war namespace FloatConvert { typedef int a[(int)42.3]; typedef int a[(int)42.997]; - typedef int b[(long long)4e20]; // expected-warning {{variable length}} expected-error {{variable length}} expected-warning {{'long long' is an extension}} + typedef int b[(long long)4e20]; // expected-warning {{variable length}} expected-error {{variable length}} expected-warning {{'long long' is a C++11 extension}} } // PR12626 diff --git a/test/SemaCXX/constexpr-turing.cpp b/test/SemaCXX/constexpr-turing.cpp index c5153788adfdc..07c04eff30839 100644 --- a/test/SemaCXX/constexpr-turing.cpp +++ b/test/SemaCXX/constexpr-turing.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify -std=c++11 %s +// expected-no-diagnostics // A direct proof that constexpr is Turing-complete, once DR1454 is implemented. diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index f503d01f360d3..ecbe7bf5b9edd 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -135,12 +135,12 @@ class InitializeUsingSelfTest { TwoInOne D; int E; InitializeUsingSelfTest(int F) - : A(A), // expected-warning {{field is uninitialized when used here}} - B((((B)))), // expected-warning {{field is uninitialized when used here}} - C(A && InitializeUsingSelfTest::C), // expected-warning {{field is uninitialized when used here}} - D(D, // expected-warning {{field is uninitialized when used here}} - D), // expected-warning {{field is uninitialized when used here}} - E(IntParam(E)) {} // expected-warning {{field is uninitialized when used here}} + : A(A), // expected-warning {{field 'A' is uninitialized when used here}} + B((((B)))), // expected-warning {{field 'B' is uninitialized when used here}} + C(A && InitializeUsingSelfTest::C), // expected-warning {{field 'C' is uninitialized when used here}} + D(D, // expected-warning {{field 'D' is uninitialized when used here}} + D), // expected-warning {{field 'D' is uninitialized when used here}} + E(IntParam(E)) {} // expected-warning {{field 'E' is uninitialized when used here}} }; int IntWrapper(int &i) { return 0; }; @@ -160,8 +160,8 @@ class CopyConstructorTest { bool A, B, C; CopyConstructorTest(const CopyConstructorTest& rhs) : A(rhs.A), - B(B), // expected-warning {{field is uninitialized when used here}} - C(rhs.C || C) { } // expected-warning {{field is uninitialized when used here}} + B(B), // expected-warning {{field 'B' is uninitialized when used here}} + C(rhs.C || C) { } // expected-warning {{field 'C' is uninitialized when used here}} }; // Make sure we aren't marking default constructors when we shouldn't be. diff --git a/test/SemaCXX/crashes.cpp b/test/SemaCXX/crashes.cpp index d02704c87c74b..f5682bd74d92c 100644 --- a/test/SemaCXX/crashes.cpp +++ b/test/SemaCXX/crashes.cpp @@ -136,3 +136,38 @@ cc_YCbCr cc_hsl::YCbCr() } } + +namespace test1 { + int getString(const int*); + template<int a> class ELFObjectFile { + const int* sh; + ELFObjectFile() { + switch (*sh) { + } + int SectionName(getString(sh)); + } + }; +} + +namespace test2 { + struct fltSemantics ; + const fltSemantics &foobar(); + void VisitCastExpr(int x) { + switch (x) { + case 42: + const fltSemantics &Sem = foobar(); + } + } +} + +namespace test3 { + struct nsCSSRect { + }; + static int nsCSSRect::* sides; + nsCSSRect dimenX; + void ParseBoxCornerRadii(int y) { + switch (y) { + } + int& x = dimenX.*sides; + } +} diff --git a/test/SemaCXX/cstyle-cast.cpp b/test/SemaCXX/cstyle-cast.cpp index 12495ecdc5c19..468c8ecb23c42 100644 --- a/test/SemaCXX/cstyle-cast.cpp +++ b/test/SemaCXX/cstyle-cast.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// REQUIRES: LP64 struct A {}; diff --git a/test/SemaCXX/cxx0x-delegating-ctors.cpp b/test/SemaCXX/cxx0x-delegating-ctors.cpp index 2d49f0fc599d3..a34ee4fcb024f 100644 --- a/test/SemaCXX/cxx0x-delegating-ctors.cpp +++ b/test/SemaCXX/cxx0x-delegating-ctors.cpp @@ -33,7 +33,9 @@ foo::foo (const float &f) : foo(&f) { //expected-error{{creates a delegation cyc //expected-note{{which delegates to}} } -foo::foo (char) : i(3), foo(3) { // expected-error{{must appear alone}} +foo::foo (char) : + i(3), + foo(3) { // expected-error{{must appear alone}} } // This should not cause an infinite loop diff --git a/test/SemaCXX/cxx0x-initializer-constructor.cpp b/test/SemaCXX/cxx0x-initializer-constructor.cpp index 223e140ffc020..a657ec81a140f 100644 --- a/test/SemaCXX/cxx0x-initializer-constructor.cpp +++ b/test/SemaCXX/cxx0x-initializer-constructor.cpp @@ -304,3 +304,19 @@ namespace init_list_default { }; B b {}; // calls default constructor } + + +// <rdar://problem/11974632> +namespace rdar11974632 { + struct X { + X(const X&) = delete; + X(int); + }; + + template<typename T> + struct Y { + X x{1}; + }; + + Y<int> yi; +} diff --git a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index f11e19ae6f2c4..0962253b988cc 100644 --- a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -187,3 +187,7 @@ namespace rdar11948732 { XCtorInit xc = { xi, xi }; } } + +namespace PR14272 { + auto x { { 0, 0 } }; // expected-error {{cannot deduce actual type for variable 'x' with type 'auto' from initializer list}} +} diff --git a/test/SemaCXX/cxx11-crashes.cpp b/test/SemaCXX/cxx11-crashes.cpp new file mode 100644 index 0000000000000..bd51af1da2fa5 --- /dev/null +++ b/test/SemaCXX/cxx11-crashes.cpp @@ -0,0 +1,76 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s + +// rdar://12240916 stack overflow. +namespace rdar12240916 { + +struct S2 { + S2(const S2&); + S2(); +}; + +struct S { // expected-note {{not complete}} + S x; // expected-error {{incomplete type}} + S2 y; +}; + +S foo() { + S s; + return s; +} + +struct S3; // expected-note {{forward declaration}} + +struct S4 { + S3 x; // expected-error {{incomplete type}} + S2 y; +}; + +struct S3 { + S4 x; + S2 y; +}; + +S4 foo2() { + S4 s; + return s; +} + +} + +// rdar://12542261 stack overflow. +namespace rdar12542261 { + +template <class _Tp> +struct check_complete +{ + static_assert(sizeof(_Tp) > 0, "Type must be complete."); +}; + + +template<class _Rp> +class function // expected-note 2 {{candidate}} +{ +public: + template<class _Fp> + function(_Fp, typename check_complete<_Fp>::type* = 0); // expected-note {{candidate}} +}; + +void foobar() +{ + auto LeftCanvas = new Canvas(); // expected-error {{unknown type name}} + function<void()> m_OnChange = [&, LeftCanvas]() { }; // expected-error {{no viable conversion}} +} + +} + +namespace b6981007 { + struct S {}; // expected-note 3{{candidate}} + void f() { + S s(1, 2, 3); // expected-error {{no matching}} + for (auto x : s) { + // We used to attempt to evaluate the initializer of this variable, + // and crash because it has an undeduced type. + const int &n(x); + } + } +} diff --git a/test/SemaCXX/cxx98-compat-pedantic.cpp b/test/SemaCXX/cxx98-compat-pedantic.cpp index c07f64e614d25..18fd1520ec4e3 100644 --- a/test/SemaCXX/cxx98-compat-pedantic.cpp +++ b/test/SemaCXX/cxx98-compat-pedantic.cpp @@ -32,3 +32,9 @@ int *ArraySizeConversion = new int[ConvertToInt()]; // expected-warning {{implic template<typename T> class ExternTemplate {}; extern template class ExternTemplate<int>; // expected-warning {{extern templates are incompatible with C++98}} + +long long ll1 = // expected-warning {{'long long' is incompatible with C++98}} + -42LL; // expected-warning {{'long long' is incompatible with C++98}} +unsigned long long ull1 = // expected-warning {{'long long' is incompatible with C++98}} + 42ULL; // expected-warning {{'long long' is incompatible with C++98}} + diff --git a/test/SemaCXX/cxx98-compat.cpp b/test/SemaCXX/cxx98-compat.cpp index 37341f8856190..d497d45c3e358 100644 --- a/test/SemaCXX/cxx98-compat.cpp +++ b/test/SemaCXX/cxx98-compat.cpp @@ -20,7 +20,7 @@ class Variadic2 {}; template<int ...I> // expected-warning {{variadic templates are incompatible with C++98}} class Variadic3 {}; -int alignas(8) with_alignas; // expected-warning {{'alignas' is incompatible with C++98}} +alignas(8) int with_alignas; // expected-warning {{'alignas' is incompatible with C++98}} int with_attribute [[ ]]; // expected-warning {{attributes are incompatible with C++98}} void Literals() { @@ -362,3 +362,14 @@ namespace AssignOpUnion { b y; // expected-warning {{union member 'y' with a non-trivial copy assignment operator is incompatible with C++98}} }; } + +namespace rdar11736429 { + struct X { + X(const X&) = delete; // expected-warning{{deleted function definitions are incompatible with C++98}} \ + // expected-note{{because type 'rdar11736429::X' has a user-declared constructor}} + }; + + union S { + X x; // expected-warning{{union member 'x' with a non-trivial constructor is incompatible with C++98}} + }; +} diff --git a/test/SemaCXX/dcl_ambig_res.cpp b/test/SemaCXX/dcl_ambig_res.cpp index 08867c0ea2f5f..97780e41f0c49 100644 --- a/test/SemaCXX/dcl_ambig_res.cpp +++ b/test/SemaCXX/dcl_ambig_res.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s +// PR13819 +// REQUIRES: LP64 + // [dcl.ambig.res]p1: struct S { S(int); diff --git a/test/SemaCXX/decl-expr-ambiguity.cpp b/test/SemaCXX/decl-expr-ambiguity.cpp index 0980c40cbfd57..87fd2dad316ce 100644 --- a/test/SemaCXX/decl-expr-ambiguity.cpp +++ b/test/SemaCXX/decl-expr-ambiguity.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s +// RUN: %clang_cc1 -Wno-int-to-pointer-cast -fsyntax-only -verify -pedantic-errors %s void f() { int a; diff --git a/test/SemaCXX/decltype-98.cpp b/test/SemaCXX/decltype-98.cpp index db52565e6c746..3202dfea71e28 100644 --- a/test/SemaCXX/decltype-98.cpp +++ b/test/SemaCXX/decltype-98.cpp @@ -1,3 +1,4 @@ // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s +// expected-no-diagnostics extern int x; __decltype(1) x = 3; diff --git a/test/SemaCXX/decltype-overloaded-functions.cpp b/test/SemaCXX/decltype-overloaded-functions.cpp index b0a43a999bb60..c1d01fc9af952 100644 --- a/test/SemaCXX/decltype-overloaded-functions.cpp +++ b/test/SemaCXX/decltype-overloaded-functions.cpp @@ -1,15 +1,30 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -void f(); // expected-note{{possible target for call}} -void f(int); // expected-note{{possible target for call}} +void f(); // expected-note{{possible target for call}} +void f(int); // expected-note{{possible target for call}} decltype(f) a; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{variable has incomplete type 'decltype(f())' (aka 'void')}} template<typename T> struct S { - decltype(T::f) * f; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{call to non-static member function without an object argument}} + decltype(T::f) * f; // expected-error {{call to non-static member function without an object argument}} }; struct K { - void f(); // expected-note{{possible target for call}} - void f(int); // expected-note{{possible target for call}} + void f(); + void f(int); }; S<K> b; // expected-note{{in instantiation of template class 'S<K>' requested here}} + +namespace PR13978 { + template<typename T> struct S { decltype(1) f(); }; + template<typename T> decltype(1) S<T>::f() { return 1; } + + // This case is ill-formed (no diagnostic required) because the decltype + // expressions are functionally equivalent but not equivalent. It would + // be acceptable for us to reject this case. + template<typename T> struct U { struct A {}; decltype(A{}) f(); }; + template<typename T> decltype(typename U<T>::A{}) U<T>::f() {} + + // This case is valid. + template<typename T> struct V { struct A {}; decltype(typename V<T>::A{}) f(); }; + template<typename T> decltype(typename V<T>::A{}) V<T>::f() {} +} diff --git a/test/SemaCXX/decltype-pr4444.cpp b/test/SemaCXX/decltype-pr4444.cpp index 2f95075067a4a..a5ac54bc37fea 100644 --- a/test/SemaCXX/decltype-pr4444.cpp +++ b/test/SemaCXX/decltype-pr4444.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics template<typename T, T t> struct TestStruct { diff --git a/test/SemaCXX/decltype-pr4448.cpp b/test/SemaCXX/decltype-pr4448.cpp index 9d33ce7341a24..b781b891ffb78 100644 --- a/test/SemaCXX/decltype-pr4448.cpp +++ b/test/SemaCXX/decltype-pr4448.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics template< typename T, T t, decltype(t+2) v > struct Convoluted {}; diff --git a/test/SemaCXX/decltype-this.cpp b/test/SemaCXX/decltype-this.cpp index a13416f089dd6..21b4b60ea3cee 100644 --- a/test/SemaCXX/decltype-this.cpp +++ b/test/SemaCXX/decltype-this.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// expected-no-diagnostics template<typename T, typename U> struct is_same { static const bool value = false; diff --git a/test/SemaCXX/decltype.cpp b/test/SemaCXX/decltype.cpp index a1200e08200d0..ccde3dcfb3123 100644 --- a/test/SemaCXX/decltype.cpp +++ b/test/SemaCXX/decltype.cpp @@ -28,3 +28,18 @@ template<typename T> auto f(T t) -> decltype(S<int>(t)) { using U = S<int>; return S<int>(t); } + +struct B { + B(decltype(undeclared)); // expected-error {{undeclared identifier}} +}; +struct C { + C(decltype(undeclared; // expected-error {{undeclared identifier}} \ + // expected-error {{expected ')'}} expected-note {{to match this '('}} +}; + +template<typename> +class conditional { +}; + +void foo(conditional<decltype((1),int>) { // expected-note 2 {{to match this '('}} expected-error {{expected ')'}} +} // expected-error {{expected function body after function declarator}} expected-error 2 {{expected '>'}} expected-error {{expected ')'}} diff --git a/test/SemaCXX/default-argument-temporaries.cpp b/test/SemaCXX/default-argument-temporaries.cpp index 3ab7bf4eb13d6..c0880d507e43c 100644 --- a/test/SemaCXX/default-argument-temporaries.cpp +++ b/test/SemaCXX/default-argument-temporaries.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics struct B { B(void* = 0); }; struct A { diff --git a/test/SemaCXX/defaulted-ctor-loop.cpp b/test/SemaCXX/defaulted-ctor-loop.cpp index 6416336c6eedb..bc8dfdaa3cf29 100644 --- a/test/SemaCXX/defaulted-ctor-loop.cpp +++ b/test/SemaCXX/defaulted-ctor-loop.cpp @@ -9,6 +9,6 @@ struct bar { struct foo { bar b; foo() - : b(b) // expected-warning{{field is uninitialized}} + : b(b) // expected-warning{{field 'b' is uninitialized}} {} }; diff --git a/test/SemaCXX/do-while-scope.cpp b/test/SemaCXX/do-while-scope.cpp index 2602ae12f243b..67534db36d616 100644 --- a/test/SemaCXX/do-while-scope.cpp +++ b/test/SemaCXX/do-while-scope.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics void test() { int x; diff --git a/test/SemaCXX/empty-class-layout.cpp b/test/SemaCXX/empty-class-layout.cpp index c68f2bb6fb0e6..951f16c1b0c54 100644 --- a/test/SemaCXX/empty-class-layout.cpp +++ b/test/SemaCXX/empty-class-layout.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify +// expected-no-diagnostics #define SA(n, p) int a##n[(p) ? 1 : -1] diff --git a/test/SemaCXX/exception-spec-no-exceptions.cpp b/test/SemaCXX/exception-spec-no-exceptions.cpp index 2e180706d3b91..e26e864e3d8f1 100644 --- a/test/SemaCXX/exception-spec-no-exceptions.cpp +++ b/test/SemaCXX/exception-spec-no-exceptions.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fobjc-exceptions %s +// expected-no-diagnostics // Note that we're specifically excluding -fcxx-exceptions in the command line above. diff --git a/test/SemaCXX/explicit.cpp b/test/SemaCXX/explicit.cpp index 477463771e886..5ce2cf19132ca 100644 --- a/test/SemaCXX/explicit.cpp +++ b/test/SemaCXX/explicit.cpp @@ -40,10 +40,10 @@ namespace Conversion { void testExplicit() { // Taken from 12.3.2p2 - class Y { }; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Conversion::Z' to 'const Conversion::Y &' for 1st argument}} \ - expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'Conversion::Z' to 'Conversion::Y &&' for 1st argument}} \ - expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Conversion::Z' to 'const Conversion::Y &' for 1st argument}} \ - expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'Conversion::Z' to 'Conversion::Y &&' for 1st argument}} + class Y { }; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Z' to 'const Y &' for 1st argument}} \ + expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'Z' to 'Y &&' for 1st argument}} \ + expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'Z' to 'const Y &' for 1st argument}} \ + expected-note {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'Z' to 'Y &&' for 1st argument}} struct Z { explicit operator Y() const; @@ -52,7 +52,7 @@ namespace Conversion { Z z; // 13.3.1.4p1 & 8.5p16: - Y y2 = z; // expected-error {{no viable conversion from 'Conversion::Z' to 'Conversion::Y'}} + Y y2 = z; // expected-error {{no viable conversion from 'Z' to 'Y'}} Y y3 = (Y)z; Y y4 = Y(z); Y y5 = static_cast<Y>(z); @@ -62,7 +62,7 @@ namespace Conversion { int i3 = static_cast<int>(z); int i4(z); // 13.3.1.6p1 & 8.5.3p5: - const Y& y6 = z; // expected-error {{no viable conversion from 'Conversion::Z' to 'const Conversion::Y'}} + const Y& y6 = z; // expected-error {{no viable conversion from 'Z' to 'const Y'}} const int& y7(z); } @@ -78,7 +78,7 @@ namespace Conversion { NotBool n; (void) (1 + b); - (void) (1 + n); // expected-error {{invalid operands to binary expression ('int' and 'Conversion::NotBool')}} + (void) (1 + n); // expected-error {{invalid operands to binary expression ('int' and 'NotBool')}} // 5.3.1p9: (void) (!b); @@ -105,7 +105,7 @@ namespace Conversion { // 6.4.2p2: switch (b) {} // expected-warning {{switch condition has boolean value}} - switch (n) {} // expected-error {{switch condition type 'Conversion::NotBool' requires explicit conversion to 'bool'}} \ + switch (n) {} // expected-error {{switch condition type 'NotBool' requires explicit conversion to 'bool'}} \ expected-warning {{switch condition has boolean value}} // 6.5.1: @@ -135,7 +135,7 @@ namespace Conversion { NotInt ni; new int[i]; - new int[ni]; // expected-error {{array size expression of type 'Conversion::NotInt' requires explicit conversion to type 'int'}} + new int[ni]; // expected-error {{array size expression of type 'NotInt' requires explicit conversion to type 'int'}} } void testDelete() @@ -152,7 +152,7 @@ namespace Conversion { NotPtr np; delete p; - delete np; // expected-error {{cannot delete expression of type 'Conversion::NotPtr'}} + delete np; // expected-error {{cannot delete expression of type 'NotPtr'}} } void testFunctionPointer() @@ -170,6 +170,6 @@ namespace Conversion { FP fp; NotFP nfp; fp(1); - nfp(1); // expected-error {{type 'Conversion::NotFP' does not provide a call operator}} + nfp(1); // expected-error {{type 'NotFP' does not provide a call operator}} } } diff --git a/test/SemaCXX/for-range-dereference.cpp b/test/SemaCXX/for-range-dereference.cpp new file mode 100644 index 0000000000000..bf3187da30e2e --- /dev/null +++ b/test/SemaCXX/for-range-dereference.cpp @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +struct Data { }; +struct T { + Data *begin(); + Data *end(); +}; + +struct NoBegin { + Data *end(); +}; + +struct DeletedEnd : public T { + Data *begin(); + Data *end() = delete; //expected-note {{function has been explicitly marked deleted here}} +}; + +struct DeletedADLBegin { }; + +int* begin(DeletedADLBegin) = delete; //expected-note {{candidate function has been explicitly deleted}} \ + expected-note 5 {{candidate function not viable: no known conversion}} + +struct PrivateEnd { + Data *begin(); + + private: + Data *end(); // expected-note 2 {{declared private here}} +}; + +struct ADLNoEnd { }; +Data * begin(ADLNoEnd); // expected-note 6 {{candidate function not viable: no known conversion}} + +struct OverloadedStar { + T operator*(); +}; + +void f() { + T t; + for (auto i : t) { } + T *pt; + for (auto i : pt) { } // expected-error{{invalid range expression of type 'T *'; did you mean to dereference it with '*'?}} + + int arr[10]; + for (auto i : arr) { } + int (*parr)[10]; + for (auto i : parr) { }// expected-error{{invalid range expression of type 'int (*)[10]'; did you mean to dereference it with '*'?}} + + NoBegin NB; + for (auto i : NB) { }// expected-error{{range type 'NoBegin' has 'end' member but no 'begin' member}} + NoBegin *pNB; + for (auto i : pNB) { }// expected-error{{invalid range expression of type 'NoBegin *'; no viable 'begin' function available}} + NoBegin **ppNB; + for (auto i : ppNB) { }// expected-error{{invalid range expression of type 'NoBegin **'; no viable 'begin' function available}} + NoBegin *****pppppNB; + for (auto i : pppppNB) { }// expected-error{{invalid range expression of type 'NoBegin *****'; no viable 'begin' function available}} + + ADLNoEnd ANE; + for (auto i : ANE) { } // expected-error{{invalid range expression of type 'ADLNoEnd'; no viable 'end' function available}} + ADLNoEnd *pANE; + for (auto i : pANE) { } // expected-error{{invalid range expression of type 'ADLNoEnd *'; no viable 'begin' function available}} + + DeletedEnd DE; + for (auto i : DE) { } // expected-error{{attempt to use a deleted function}} \ +expected-note {{when looking up 'end' function for range expression of type 'DeletedEnd'}} + DeletedEnd *pDE; + + for (auto i : pDE) { } // expected-error {{invalid range expression of type 'DeletedEnd *'; no viable 'begin' function available}} + + PrivateEnd PE; + // FIXME: This diagnostic should be improved, as it does not specify that + // the range is invalid. + for (auto i : PE) { } // expected-error{{'end' is a private member of 'PrivateEnd'}} + + PrivateEnd *pPE; + for (auto i : pPE) { }// expected-error {{invalid range expression of type 'PrivateEnd *'}} + // expected-error@-1 {{'end' is a private member of 'PrivateEnd'}} + + DeletedADLBegin DAB; + for (auto i : DAB) { } // expected-error {{call to deleted function 'begin'}}\ + expected-note {{when looking up 'begin' function for range expression of type 'DeletedADLBegin'}} + + OverloadedStar OS; + for (auto i : *OS) { } + + for (auto i : OS) { } // expected-error {{invalid range expression of type 'OverloadedStar'; did you mean to dereference it with '*'?}} + + for (Data *p : pt) { } // expected-error {{invalid range expression of type 'T *'; did you mean to dereference it with '*'?}} + // expected-error@-1 {{no viable conversion from 'Data' to 'Data *'}} + // expected-note@4 {{selected 'begin' function with iterator type 'Data *'}} +} diff --git a/test/SemaCXX/for-range-examples.cpp b/test/SemaCXX/for-range-examples.cpp index 8bda51062a40b..953c98b4c8180 100644 --- a/test/SemaCXX/for-range-examples.cpp +++ b/test/SemaCXX/for-range-examples.cpp @@ -115,7 +115,7 @@ namespace map_range { } } -#define assert(b) if (!b) { return 1; } +#define assert(b) if (!(b)) { return 1; } int main() { int total = 0; diff --git a/test/SemaCXX/for-range-no-std.cpp b/test/SemaCXX/for-range-no-std.cpp index fa42ca45a58fb..66b445e4d83b6 100644 --- a/test/SemaCXX/for-range-no-std.cpp +++ b/test/SemaCXX/for-range-no-std.cpp @@ -31,10 +31,10 @@ NS::iter end(NS::NoADL); void f() { int a[] = {1, 2, 3}; for (auto b : S()) {} // ok - for (auto b : T()) {} // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type}} + for (auto b : T()) {} // expected-error {{invalid range expression of type 'T'}} for (auto b : a) {} // ok for (int b : NS::ADL()) {} // ok - for (int b : NS::NoADL()) {} // expected-error {{no matching function for call to 'begin'}} expected-note {{range has type}} + for (int b : NS::NoADL()) {} // expected-error {{invalid range expression of type 'NS::NoADL'}} } void PR11601() { diff --git a/test/SemaCXX/format-strings.cpp b/test/SemaCXX/format-strings.cpp index 6b0df2935378f..299aa81bb1612 100644 --- a/test/SemaCXX/format-strings.cpp +++ b/test/SemaCXX/format-strings.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wformat-nonliteral -pedantic -fblocks %s #include <stdarg.h> @@ -75,3 +75,61 @@ int Foo::printf2(const char *fmt, ...) { return 0; } + + +namespace Templates { + template<typename T> + void my_uninstantiated_print(const T &arg) { + printf("%d", arg); // no-warning + } + + template<typename T> + void my_print(const T &arg) { + printf("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} + } + + void use_my_print() { + my_print("abc"); // expected-note {{requested here}} + } + + + template<typename T> + class UninstantiatedPrinter { + public: + static void print(const T &arg) { + printf("%d", arg); // no-warning + } + }; + + template<typename T> + class Printer { + void format(const char *fmt, ...) __attribute__((format(printf,2,3))); + public: + + void print(const T &arg) { + format("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} + } + }; + + void use_class(Printer<const char *> &p) { + p.print("abc"); // expected-note {{requested here}} + } + + + extern void (^block_print)(const char * format, ...) __attribute__((format(printf, 1, 2))); + + template<typename T> + void uninstantiated_call_block_print(const T &arg) { + block_print("%d", arg); // no-warning + } + + template<typename T> + void call_block_print(const T &arg) { + block_print("%d", arg); // expected-warning {{format specifies type 'int' but the argument has type 'const char *'}} + } + + void use_block_print() { + call_block_print("abc"); // expected-note {{requested here}} + } +} + diff --git a/test/SemaCXX/friend-out-of-line.cpp b/test/SemaCXX/friend-out-of-line.cpp index 56b2daab4c4f1..ab75a4f8ca446 100644 --- a/test/SemaCXX/friend-out-of-line.cpp +++ b/test/SemaCXX/friend-out-of-line.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics // <rdar://problem/10204947> namespace N { diff --git a/test/SemaCXX/function-type-qual.cpp b/test/SemaCXX/function-type-qual.cpp index 73613aef8d016..ccb57472925d6 100644 --- a/test/SemaCXX/function-type-qual.cpp +++ b/test/SemaCXX/function-type-qual.cpp @@ -26,3 +26,6 @@ class C { void (C::*mpf)() const; cfn C::*mpg; + +// Don't crash! +void (PR14171)() const; // expected-error {{non-member function cannot have 'const' qualifier}} diff --git a/test/SemaCXX/functional-cast.cpp b/test/SemaCXX/functional-cast.cpp index 61e4da3da9b8a..f8e0c465875ef 100644 --- a/test/SemaCXX/functional-cast.cpp +++ b/test/SemaCXX/functional-cast.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// REQUIRES: LP64 // ------------ not interpreted as C-style cast ------------ diff --git a/test/SemaCXX/gnu-case-ranges.cpp b/test/SemaCXX/gnu-case-ranges.cpp index b082e3a6c1c06..c613cecbc5a9f 100644 --- a/test/SemaCXX/gnu-case-ranges.cpp +++ b/test/SemaCXX/gnu-case-ranges.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify -Wno-covered-switch-default %s +// expected-no-diagnostics enum E { one, diff --git a/test/SemaCXX/goto2.cpp b/test/SemaCXX/goto2.cpp index 01ea031ac2c1c..b42a611182415 100644 --- a/test/SemaCXX/goto2.cpp +++ b/test/SemaCXX/goto2.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics //PR9463 int subfun(const char *text) { diff --git a/test/SemaCXX/implicit-exception-spec.cpp b/test/SemaCXX/implicit-exception-spec.cpp index b29cff5c5d12b..e26f985f0d0ae 100644 --- a/test/SemaCXX/implicit-exception-spec.cpp +++ b/test/SemaCXX/implicit-exception-spec.cpp @@ -30,20 +30,17 @@ namespace InClassInitializers { bool x = noexcept(TemplateArg()); // And within a nested class. - // FIXME: The diagnostic location is terrible here. - struct Nested { + struct Nested { // expected-error {{cannot be used by non-static data member initializer}} struct Inner { - int n = ExceptionIf<noexcept(Nested())>::f(); - } inner; // expected-error {{cannot be used by non-static data member initializer}} + int n = ExceptionIf<noexcept(Nested())>::f(); // expected-note {{implicit default constructor for 'InClassInitializers::Nested' first required here}} + } inner; }; - bool y = noexcept(Nested()); - bool z = noexcept(Nested::Inner()); struct Nested2 { struct Inner; int n = Inner().n; // expected-error {{cannot be used by non-static data member initializer}} struct Inner { - int n = ExceptionIf<noexcept(Nested())>::f(); + int n = ExceptionIf<noexcept(Nested2())>::f(); } inner; }; } diff --git a/test/SemaCXX/indirect-goto.cpp b/test/SemaCXX/indirect-goto.cpp index 5b3fac4a658f0..cb2213d78dd7f 100644 --- a/test/SemaCXX/indirect-goto.cpp +++ b/test/SemaCXX/indirect-goto.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics namespace test1 { // Make sure this doesn't crash. diff --git a/test/SemaCXX/issue547.cpp b/test/SemaCXX/issue547.cpp index ab03a155d3669..bfec6e080ba51 100644 --- a/test/SemaCXX/issue547.cpp +++ b/test/SemaCXX/issue547.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// expected-no-diagnostics template<typename T> struct classify_function { diff --git a/test/SemaCXX/lambda-expressions.cpp b/test/SemaCXX/lambda-expressions.cpp index 0fd634502bc9c..6f92373a69540 100644 --- a/test/SemaCXX/lambda-expressions.cpp +++ b/test/SemaCXX/lambda-expressions.cpp @@ -77,18 +77,21 @@ namespace ImplicitCapture { struct G { G(); G(G&); int a; }; // expected-note 6 {{not viable}} G g; [=]() { const G* gg = &g; return gg->a; }; - [=]() { return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error {{no matching constructor for initialization of 'ImplicitCapture::G'}} - (void)^{ return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error 2 {{no matching constructor for initialization of 'const ImplicitCapture::G'}} + [=]() { return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error {{no matching constructor for initialization of 'G'}} + (void)^{ return [=]{ const G* gg = &g; return gg->a; }(); }; // expected-error 2 {{no matching constructor for initialization of 'const G'}} const int h = a; // expected-note {{declared}} []() { return h; }; // expected-error {{variable 'h' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} - // The exemption for variables which can appear in constant expressions - // applies only to objects (and not to references). - // FIXME: This might be a bug in the standard. - static int i; - constexpr int &ref_i = i; // expected-note {{declared}} + // References can appear in constant expressions if they are initialized by + // reference constant expressions. + int i; + int &ref_i = i; // expected-note {{declared}} [] { return ref_i; }; // expected-error {{variable 'ref_i' cannot be implicitly captured in a lambda with no capture-default specified}} expected-note {{lambda expression begins here}} + + static int j; + int &ref_j = j; + [] { return ref_j; }; // ok } } @@ -221,3 +224,15 @@ namespace VariadicPackExpansion { template void nested2(int); // ok template void nested2(int, int); // expected-note {{in instantiation of}} } + +namespace PR13860 { + void foo() { + auto x = PR13860UndeclaredIdentifier(); // expected-error {{use of undeclared identifier 'PR13860UndeclaredIdentifier'}} + auto y = [x]() { }; + static_assert(sizeof(y), ""); + } +} + +namespace PR13854 { + auto l = [](void){}; +} diff --git a/test/SemaCXX/libstdcxx_atomic_ns_hack.cpp b/test/SemaCXX/libstdcxx_atomic_ns_hack.cpp new file mode 100644 index 0000000000000..4e4523f853228 --- /dev/null +++ b/test/SemaCXX/libstdcxx_atomic_ns_hack.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s + +// libstdc++ 4.6.x contains a bug where it defines std::__atomic[0,1,2] as a +// non-inline namespace, then selects one of those namespaces and reopens it +// as inline, as a strange way of providing something like a using-directive. +// Clang has an egregious hack to work around the problem, by allowing a +// namespace to be converted from non-inline to inline in this one specific +// case. + +#ifdef BE_THE_HEADER + +#pragma clang system_header + +namespace std { + namespace __atomic0 { + typedef int foobar; + } + namespace __atomic1 { + typedef void foobar; + } + + inline namespace __atomic0 {} +} + +#else + +#define BE_THE_HEADER +#include "libstdcxx_atomic_ns_hack.cpp" + +std::foobar fb; + +using T = void; // expected-note {{here}} +using T = std::foobar; // expected-error {{different types ('std::foobar' (aka 'int') vs 'void')}} + +#endif diff --git a/test/SemaCXX/libstdcxx_common_type_hack.cpp b/test/SemaCXX/libstdcxx_common_type_hack.cpp new file mode 100644 index 0000000000000..e9cb22f9dabfa --- /dev/null +++ b/test/SemaCXX/libstdcxx_common_type_hack.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify + +// This is a test for an egregious hack in Clang that works around +// an issue with GCC's <type_traits> implementation. std::common_type +// relies on pre-standard rules for decltype(), in which it doesn't +// produce reference types so frequently. + +#ifdef BE_THE_HEADER + +#pragma GCC system_header +namespace std { + template<typename T> T &&declval(); + + template<typename...Ts> struct common_type {}; + template<typename A, typename B> struct common_type<A, B> { + // Under the rules in the standard, this always produces a + // reference type. + typedef decltype(true ? declval<A>() : declval<B>()) type; + }; +} + +#else + +#define BE_THE_HEADER +#include "libstdcxx_common_type_hack.cpp" + +using T = int; +using T = std::common_type<int, int>::type; + +using U = int; // expected-note {{here}} +using U = decltype(true ? std::declval<int>() : std::declval<int>()); // expected-error {{different types}} + +#endif diff --git a/test/SemaCXX/libstdcxx_is_pod_hack.cpp b/test/SemaCXX/libstdcxx_is_pod_hack.cpp index 3ac233627ccb7..1ba3721c8c2ef 100644 --- a/test/SemaCXX/libstdcxx_is_pod_hack.cpp +++ b/test/SemaCXX/libstdcxx_is_pod_hack.cpp @@ -8,6 +8,7 @@ template<typename T> struct __is_pod { + __is_pod() {} }; __is_pod<int> ipi; @@ -28,6 +29,13 @@ struct test_is_signed { bool check_signed = test_is_signed::__is_signed; -#if __has_feature(is_pod) -# error __is_pod won't work now anyway +template<bool B> struct must_be_true {}; +template<> struct must_be_true<false>; + +void foo() { + bool b = __is_pod(int); + must_be_true<__is_pod(int)> mbt; +} +#if !__has_feature(is_pod) +# error __is_pod should still be available. #endif diff --git a/test/SemaCXX/local-classes.cpp b/test/SemaCXX/local-classes.cpp index 500b2197ef35f..f4ca79159dc96 100644 --- a/test/SemaCXX/local-classes.cpp +++ b/test/SemaCXX/local-classes.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics namespace PR6382 { int foo() diff --git a/test/SemaCXX/lookup-member.cpp b/test/SemaCXX/lookup-member.cpp index c75b185bcc420..39f5a15d0811a 100644 --- a/test/SemaCXX/lookup-member.cpp +++ b/test/SemaCXX/lookup-member.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics namespace A { class String; diff --git a/test/SemaCXX/member-expr-anonymous-union.cpp b/test/SemaCXX/member-expr-anonymous-union.cpp index 6e35eb2b14d7d..246afee239904 100644 --- a/test/SemaCXX/member-expr-anonymous-union.cpp +++ b/test/SemaCXX/member-expr-anonymous-union.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify +// expected-no-diagnostics // PR5543 struct A { int x; union { int* y; float* z; }; }; struct B : A {int a;}; diff --git a/test/SemaCXX/member-expr-static.cpp b/test/SemaCXX/member-expr-static.cpp index 7ed60f7a17b78..d4c6c0b6da2f5 100644 --- a/test/SemaCXX/member-expr-static.cpp +++ b/test/SemaCXX/member-expr-static.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics typedef void (*thread_continue_t)(); extern "C" { diff --git a/test/SemaCXX/member-pointer-size.cpp b/test/SemaCXX/member-pointer-size.cpp index 3aa1eaf5f256a..8b595237fcab7 100644 --- a/test/SemaCXX/member-pointer-size.cpp +++ b/test/SemaCXX/member-pointer-size.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify // RUN: %clang_cc1 -triple i686-unknown-unknown %s -fsyntax-only -verify +// expected-no-diagnostics #include <stddef.h> struct A; diff --git a/test/SemaCXX/missing-header.cpp b/test/SemaCXX/missing-header.cpp index 5b3915b865cd6..a1048fee46eb5 100644 --- a/test/SemaCXX/missing-header.cpp +++ b/test/SemaCXX/missing-header.cpp @@ -4,6 +4,6 @@ class AnalysisDeclContext {}; static ControlFlowKind CheckFallThrough(AnalysisDeclContext &AC) { - if (const AsmStmt *AS = dyn_cast<AsmStmt>(S)) {} + if (const GCCAsmStmt *AS = dyn_cast<GCCAsmStmt>(S)) {} bool NoReturnEdge = false; } diff --git a/test/SemaCXX/ms-exception-spec.cpp b/test/SemaCXX/ms-exception-spec.cpp index bda56f5468d4a..1be8ec2936908 100644 --- a/test/SemaCXX/ms-exception-spec.cpp +++ b/test/SemaCXX/ms-exception-spec.cpp @@ -1,3 +1,4 @@ // RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions +// expected-no-diagnostics void f() throw(...) { } diff --git a/test/SemaCXX/ms-interface.cpp b/test/SemaCXX/ms-interface.cpp new file mode 100644 index 0000000000000..3625f7027aa47 --- /dev/null +++ b/test/SemaCXX/ms-interface.cpp @@ -0,0 +1,77 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -Wno-microsoft -std=c++11 + +__interface I1 { + // expected-error@+1 {{user-declared constructor is not permitted within an interface type}} + I1(); + // expected-error@+1 {{user-declared destructor is not permitted within an interface type}} + ~I1(); + virtual void fn1() const; + // expected-error@+1 {{operator 'operator!' is not permitted within an interface type}} + bool operator!(); + // expected-error@+1 {{operator 'operator int' is not permitted within an interface type}} + operator int(); + // expected-error@+1 {{nested class I1::<anonymous> is not permitted within an interface type}} + struct { int a; }; + void fn2() { + struct A { }; // should be ignored: not a nested class + } +protected: // expected-error {{interface types cannot specify 'protected' access}} + typedef void void_t; + using int_t = int; +private: // expected-error {{interface types cannot specify 'private' access}} + static_assert(true, "oops"); +}; + +__interface I2 { + // expected-error@+1 {{data member 'i' is not permitted within an interface type}} + int i; + // expected-error@+1 {{static member function 'fn1' is not permitted within an interface type}} + static int fn1(); +private: // expected-error {{interface types cannot specify 'private' access}} + // expected-error@+1 {{non-public member function 'fn2' is not permitted within an interface type}} + void fn2(); +protected: // expected-error {{interface types cannot specify 'protected' access}} + // expected-error@+1 {{non-public member function 'fn3' is not permitted within an interface type}} + void fn3(); +public: + void fn4(); +}; + +// expected-error@+1 {{'final' keyword not permitted with interface types}} +__interface I3 final { +}; + +__interface I4 : I1, I2 { + void fn1() const override; + // expected-error@+1 {{'final' keyword not permitted with interface types}} + void fn2() final; +}; + +// expected-error@+1 {{interface type cannot inherit from non-public 'interface I1'}} +__interface I5 : private I1 { +}; + +template <typename X> +__interface I6 : X { +}; + +struct S { }; +class C { }; +__interface I { }; + +static_assert(!__is_interface_class(S), "oops"); +static_assert(!__is_interface_class(C), "oops"); +static_assert(__is_interface_class(I), "oops"); + +// expected-error@55 {{interface type cannot inherit from 'struct S'}} +// expected-note@+1 {{in instantiation of template class 'I6<S>' requested here}} +struct S1 : I6<S> { +}; + +// expected-error@55 {{interface type cannot inherit from 'class C'}} +// expected-note@+1 {{in instantiation of template class 'I6<C>' requested here}} +class C1 : I6<C> { +}; + +class C2 : I6<I> { +}; diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 4e1abc5e5bc89..7239646d8d7e8 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -93,8 +93,7 @@ void f3() { } // make sure the following doesn't hit any asserts -void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} \ - expected-error {{variable has incomplete type 'void'}} +void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} typedef void C2::f5(int); // expected-error{{typedef declarator cannot be qualified}} @@ -160,7 +159,7 @@ namespace N { void f(); // FIXME: if we move this to a separate definition of N, things break! } -void ::global_func2(int) { } // expected-warning{{extra qualification on member 'global_func2'}} +void ::global_func2(int) { } // expected-error{{extra qualification on member 'global_func2'}} void N::f() { } // okay @@ -246,15 +245,15 @@ namespace PR7133 { } class CLASS { - void CLASS::foo2(); // expected-warning {{extra qualification on member 'foo2'}} + void CLASS::foo2(); // expected-error {{extra qualification on member 'foo2'}} }; namespace PR8159 { class B { }; class A { - int A::a; // expected-warning{{extra qualification on member 'a'}} - static int A::b; // expected-warning{{extra qualification on member 'b'}} + int A::a; // expected-error{{extra qualification on member 'a'}} + static int A::b; // expected-error{{extra qualification on member 'b'}} int ::c; // expected-error{{non-friend class member 'c' cannot have a qualified name}} }; } diff --git a/test/SemaCXX/new-delete-0x.cpp b/test/SemaCXX/new-delete-0x.cpp index dcc2e9b8b12a3..9e3b4928b1415 100644 --- a/test/SemaCXX/new-delete-0x.cpp +++ b/test/SemaCXX/new-delete-0x.cpp @@ -27,6 +27,11 @@ void bad_news(int *ip) void good_deletes() { delete [&]{ return (int*)0; }(); - // FIXME: This appears to be legal. - delete []{ return (int*)0; }(); // unexpected-error {{expected expression}} +} + +void bad_deletes() +{ + // 'delete []' is always array delete, per [expr.delete]p1. + // FIXME: Give a better diagnostic. + delete []{ return (int*)0; }(); // expected-error {{expected expression}} } diff --git a/test/SemaCXX/new-delete-predefined-decl-2.cpp b/test/SemaCXX/new-delete-predefined-decl-2.cpp index 981476d4fd217..c2dfc77d01fba 100644 --- a/test/SemaCXX/new-delete-predefined-decl-2.cpp +++ b/test/SemaCXX/new-delete-predefined-decl-2.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -DQUALIFIED -fsyntax-only -verify %s +// expected-no-diagnostics // PR5904 void f0(int *ptr) { diff --git a/test/SemaCXX/new-delete-predefined-decl.cpp b/test/SemaCXX/new-delete-predefined-decl.cpp index 20b15b729cd04..ae10065361128 100644 --- a/test/SemaCXX/new-delete-predefined-decl.cpp +++ b/test/SemaCXX/new-delete-predefined-decl.cpp @@ -1,5 +1,6 @@ // RUN: %clang_cc1 -DTEMPLATE_OVERLOAD -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics #include <stddef.h> diff --git a/test/SemaCXX/no-warn-composite-pointer-type.cpp b/test/SemaCXX/no-warn-composite-pointer-type.cpp new file mode 100644 index 0000000000000..f33f60de9fdd4 --- /dev/null +++ b/test/SemaCXX/no-warn-composite-pointer-type.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -Wno-compare-distinct-pointer-types -verify %s +// expected-no-diagnostics +// rdar://12501960 + +void Foo(int **thing, const int **thingMax) +{ + if ((thing + 3) > thingMax) + return; +} diff --git a/test/SemaCXX/no-wchar.cpp b/test/SemaCXX/no-wchar.cpp new file mode 100644 index 0000000000000..291b657f51abe --- /dev/null +++ b/test/SemaCXX/no-wchar.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple i386-pc-win32 -fsyntax-only -fno-wchar -verify %s +wchar_t x; // expected-error {{unknown type name 'wchar_t'}} + +typedef unsigned short wchar_t; +void foo(const wchar_t* x); + +void bar() { + foo(L"wide string literal"); +} diff --git a/test/SemaCXX/null_in_arithmetic_ops.cpp b/test/SemaCXX/null_in_arithmetic_ops.cpp index a6c0dbfc6560e..a919213fb2085 100644 --- a/test/SemaCXX/null_in_arithmetic_ops.cpp +++ b/test/SemaCXX/null_in_arithmetic_ops.cpp @@ -90,4 +90,6 @@ void f() { b = e == NULL || NULL == e || e != NULL || NULL != e; b = f == NULL || NULL == f || f != NULL || NULL != f; b = "f" == NULL || NULL == "f" || "f" != NULL || NULL != "f"; + + return NULL; // expected-error{{void function 'f' should not return a value}} } diff --git a/test/SemaCXX/nullptr-98.cpp b/test/SemaCXX/nullptr-98.cpp index 0d624c26de709..306b2033e4568 100644 --- a/test/SemaCXX/nullptr-98.cpp +++ b/test/SemaCXX/nullptr-98.cpp @@ -1,3 +1,4 @@ // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s +// expected-no-diagnostics void f(void *); void g() { f(__nullptr); } diff --git a/test/SemaCXX/overload-value-dep-arg.cpp b/test/SemaCXX/overload-value-dep-arg.cpp index c1834a7225773..763daadc252a0 100644 --- a/test/SemaCXX/overload-value-dep-arg.cpp +++ b/test/SemaCXX/overload-value-dep-arg.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics class C { C(void*); diff --git a/test/SemaCXX/overloaded-builtin-operators-0x.cpp b/test/SemaCXX/overloaded-builtin-operators-0x.cpp index 6a5a162af679b..bf543892e43db 100644 --- a/test/SemaCXX/overloaded-builtin-operators-0x.cpp +++ b/test/SemaCXX/overloaded-builtin-operators-0x.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -std=c++11 -verify %s +// expected-no-diagnostics template <class T> struct X diff --git a/test/SemaCXX/overloaded-builtin-operators.cpp b/test/SemaCXX/overloaded-builtin-operators.cpp index ac110a3c0561c..19dc338716301 100644 --- a/test/SemaCXX/overloaded-builtin-operators.cpp +++ b/test/SemaCXX/overloaded-builtin-operators.cpp @@ -1,4 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify %s +// REQUIRES: LP64 + struct yes; struct no; diff --git a/test/SemaCXX/overloaded-operator-decl.cpp b/test/SemaCXX/overloaded-operator-decl.cpp index 4519a2d1f9adf..972e2deac29ed 100644 --- a/test/SemaCXX/overloaded-operator-decl.cpp +++ b/test/SemaCXX/overloaded-operator-decl.cpp @@ -48,3 +48,13 @@ struct PR10839 { operator int; // expected-error{{'operator int' cannot be the name of a variable or data member}} int operator+; // expected-error{{'operator+' cannot be the name of a variable or data member}} }; + +namespace PR14120 { + struct A { + static void operator()(int& i) { ++i; } // expected-error{{overloaded 'operator()' cannot be a static member function}} + }; + void f() { + int i = 0; + A()(i); + } +} diff --git a/test/SemaCXX/pragma-pack.cpp b/test/SemaCXX/pragma-pack.cpp index 5c1d5c6c82af6..e468cce7f0709 100644 --- a/test/SemaCXX/pragma-pack.cpp +++ b/test/SemaCXX/pragma-pack.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple i686-apple-darwin9 -fsyntax-only -verify %s +// expected-no-diagnostics namespace rdar8745206 { diff --git a/test/SemaCXX/pragma-unused.cpp b/test/SemaCXX/pragma-unused.cpp index c9ddffafafa92..c9eaab6d3f50c 100644 --- a/test/SemaCXX/pragma-unused.cpp +++ b/test/SemaCXX/pragma-unused.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -Wunused -verify %s +// expected-no-diagnostics struct S { void m(int x, int y) { diff --git a/test/SemaCXX/pragma-visibility.cpp b/test/SemaCXX/pragma-visibility.cpp index e3ef97a744472..18c59c8c10ff4 100644 --- a/test/SemaCXX/pragma-visibility.cpp +++ b/test/SemaCXX/pragma-visibility.cpp @@ -21,3 +21,10 @@ void f() { #pragma GCC visibility push(protected) #pragma GCC visibility pop } + +namespace pr13662 { +#pragma GCC visibility push(hidden) + template<class T> class __attribute__((__visibility__("default"))) foo; + class bar { template<class T> friend class foo; }; +#pragma GCC visibility pop +} diff --git a/test/SemaCXX/prefetch-enum.cpp b/test/SemaCXX/prefetch-enum.cpp index 3c77dae70ff5d..5457bbe498fff 100644 --- a/test/SemaCXX/prefetch-enum.cpp +++ b/test/SemaCXX/prefetch-enum.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics // PR5679 enum X { A = 3 }; diff --git a/test/SemaCXX/primary-base.cpp b/test/SemaCXX/primary-base.cpp index a6cbbad2427a2..0b6aaef493cbf 100644 --- a/test/SemaCXX/primary-base.cpp +++ b/test/SemaCXX/primary-base.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics class A { virtual void f(); }; class B : virtual A { }; diff --git a/test/SemaCXX/ptrtomember-overload-resolution.cpp b/test/SemaCXX/ptrtomember-overload-resolution.cpp index 787e33022aa3e..85ed0aaa4f9e2 100644 --- a/test/SemaCXX/ptrtomember-overload-resolution.cpp +++ b/test/SemaCXX/ptrtomember-overload-resolution.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics // 13.3.3.2 Ranking implicit conversion sequences // conversion of A::* to B::* is better than conversion of A::* to C::*, diff --git a/test/SemaCXX/qualified-member-enum.cpp b/test/SemaCXX/qualified-member-enum.cpp index 83b0a5911d430..750821bfd81ce 100644 --- a/test/SemaCXX/qualified-member-enum.cpp +++ b/test/SemaCXX/qualified-member-enum.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics // Check that this doesn't crash. struct A { diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp index 028c6909210ec..4f3dab0514b9d 100644 --- a/test/SemaCXX/references.cpp +++ b/test/SemaCXX/references.cpp @@ -136,4 +136,4 @@ namespace PR8608 { } // The following crashed trying to recursively evaluate the LValue. -const int &do_not_crash = do_not_crash; // expected-warning{{variable 'do_not_crash' is uninitialized when used within its own initialization}} +const int &do_not_crash = do_not_crash; // expected-warning{{reference 'do_not_crash' is not yet bound to a value when used within its own initialization}} diff --git a/test/SemaCXX/scope-check.cpp b/test/SemaCXX/scope-check.cpp index b659de001c0f7..8fd23f4efe915 100644 --- a/test/SemaCXX/scope-check.cpp +++ b/test/SemaCXX/scope-check.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks %s -Wno-unreachable-code -// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=gnu++11 %s -Wno-unreachable-code +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fcxx-exceptions %s -Wno-unreachable-code +// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -fcxx-exceptions -std=gnu++11 %s -Wno-unreachable-code namespace test0 { struct D { ~D(); }; @@ -174,14 +174,14 @@ namespace test9 { // http://llvm.org/PR10462 namespace PR10462 { -enum MyEnum { - something_valid, - something_invalid -}; - -bool recurse() { - MyEnum K; - switch (K) { // expected-warning {{enumeration value 'something_invalid' not handled in switch}} + enum MyEnum { + something_valid, + something_invalid + }; + + bool recurse() { + MyEnum K; + switch (K) { // expected-warning {{enumeration value 'something_invalid' not handled in switch}} case something_valid: case what_am_i_thinking: // expected-error {{use of undeclared identifier}} int *X = 0; @@ -189,21 +189,88 @@ bool recurse() { } break; + } } } - namespace test10 { -
-int test() {
- static void *ps[] = { &&a0 };
- goto *&&a0; // expected-error {{goto into protected scope}}
- int a = 3; // expected-note {{jump bypasses variable initialization}}
- a0:
- return 0;
+ int test() { + static void *ps[] = { &&a0 }; + goto *&&a0; // expected-error {{goto into protected scope}} + int a = 3; // expected-note {{jump bypasses variable initialization}} + a0: + return 0; + } +} + +// pr13812 +namespace test11 { + struct C { + C(int x); + ~C(); + }; + void f(void **ip) { + static void *ips[] = { &&l0 }; + l0: // expected-note {{possible target of indirect goto}} + C c0 = 42; // expected-note {{jump exits scope of variable with non-trivial destructor}} + goto *ip; // expected-error {{indirect goto might cross protected scopes}} + } +} + +namespace test12 { + struct C { + C(int x); + ~C(); + }; + void f(void **ip) { + static void *ips[] = { &&l0 }; + const C c0 = 17; + l0: // expected-note {{possible target of indirect goto}} + const C &c1 = 42; // expected-note {{jump exits scope of variable with non-trivial destructor}} + const C &c2 = c0; + goto *ip; // expected-error {{indirect goto might cross protected scopes}} + } } +namespace test13 { + struct C { + C(int x); + ~C(); + int i; + }; + void f(void **ip) { + static void *ips[] = { &&l0 }; + l0: // expected-note {{possible target of indirect goto}} + const int &c1 = C(1).i; // expected-note {{jump exits scope of variable with non-trivial destructor}} + goto *ip; // expected-error {{indirect goto might cross protected scopes}} + } } +namespace test14 { + struct C { + C(int x); + ~C(); + operator int&() const; + }; + void f(void **ip) { + static void *ips[] = { &&l0 }; + l0: + // no warning since the C temporary is destructed before the goto. + const int &c1 = C(1); + goto *ip; + } } +// PR14225 +namespace test15 { + void f1() try { + goto x; // expected-error {{goto into protected scope}} + } catch(...) { // expected-note {{jump bypasses initialization of catch block}} + x: ; + } + void f2() try { // expected-note {{jump bypasses initialization of try block}} + x: ; + } catch(...) { + goto x; // expected-error {{goto into protected scope}} + } +} diff --git a/test/SemaCXX/short-wchar-sign.cpp b/test/SemaCXX/short-wchar-sign.cpp index 9a177c04b1043..7ce21c523cd77 100644 --- a/test/SemaCXX/short-wchar-sign.cpp +++ b/test/SemaCXX/short-wchar-sign.cpp @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -triple i386-mingw32 -fsyntax-only -pedantic -verify %s // RUN: %clang_cc1 -fshort-wchar -fsyntax-only -pedantic -verify %s // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -pedantic -verify %s +// expected-no-diagnostics // Check that short wchar_t is unsigned, and that regular wchar_t is not. int test[(wchar_t(-1)<wchar_t(0)) == (sizeof(wchar_t) == 4) ?1:-1]; diff --git a/test/SemaCXX/static-initializers.cpp b/test/SemaCXX/static-initializers.cpp index ca49fce052e36..0620f484d9cba 100644 --- a/test/SemaCXX/static-initializers.cpp +++ b/test/SemaCXX/static-initializers.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics int f() { return 10; } diff --git a/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp b/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp index 14ffcef704d92..8b24c4a3b1304 100644 --- a/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp +++ b/test/SemaCXX/switch-implicit-fallthrough-cxx98.cpp @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -Wimplicit-fallthrough %s +// XFAIL: * +// NOTE: This test is marked XFAIL until we come up with a good language design +// for a worfklow to use this warning outside of C++11. int fallthrough(int n) { switch (n / 10) { diff --git a/test/SemaCXX/switch-implicit-fallthrough-macro.cpp b/test/SemaCXX/switch-implicit-fallthrough-macro.cpp new file mode 100644 index 0000000000000..add212fcf5d85 --- /dev/null +++ b/test/SemaCXX/switch-implicit-fallthrough-macro.cpp @@ -0,0 +1,139 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wimplicit-fallthrough -DCOMMAND_LINE_FALLTHROUGH=[[clang::fallthrough]] %s + +int fallthrough_compatibility_macro_from_command_line(int n) { + switch (n) { + case 0: + n = n * 10; + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'COMMAND_LINE_FALLTHROUGH;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; + } + return n; +} + +#ifdef __clang__ +#if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough") +#define COMPATIBILITY_FALLTHROUGH [ [ /* test */ clang /* test */ \ + :: fallthrough ] ] // testing whitespace and comments in macro definition +#endif +#endif + +#ifndef COMPATIBILITY_FALLTHROUGH +#define COMPATIBILITY_FALLTHROUGH do { } while (0) +#endif + +int fallthrough_compatibility_macro_from_source(int n) { + switch (n) { + case 0: + n = n * 20; + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'COMPATIBILITY_FALLTHROUGH;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; + } + return n; +} + +// Deeper macro substitution +#define M1 [[clang::fallthrough]] +#ifdef __clang__ +#define M2 M1 +#else +#define M2 +#endif + +#define WRONG_MACRO1 clang::fallthrough +#define WRONG_MACRO2 [[clang::fallthrough] +#define WRONG_MACRO3 [[clang::fall through]] +#define WRONG_MACRO4 [[clang::fallthrough]]] + +int fallthrough_compatibility_macro_in_macro(int n) { + switch (n) { + case 0: + n = n * 20; + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'M1;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + // there was an idea that this ^ should be M2 + ; + } + return n; +} + +#undef M1 +#undef M2 +#undef COMPATIBILITY_FALLTHROUGH +#undef COMMAND_LINE_FALLTHROUGH + +int fallthrough_compatibility_macro_undefined(int n) { + switch (n) { + case 0: + n = n * 20; + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; + } +#define TOO_LATE [[clang::fallthrough]] + return n; +} +#undef TOO_LATE + +#define MACRO_WITH_HISTORY 11111111 +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY [[clang::fallthrough]] +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 2222222 + +int fallthrough_compatibility_macro_history(int n) { + switch (n) { + case 0: + n = n * 20; +#undef MACRO_WITH_HISTORY + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; +#define MACRO_WITH_HISTORY [[clang::fallthrough]] + } + return n; +} + +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 11111111 +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY [[clang::fallthrough]] +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 2222222 +#undef MACRO_WITH_HISTORY + +int fallthrough_compatibility_macro_history2(int n) { + switch (n) { + case 0: + n = n * 20; +#define MACRO_WITH_HISTORY [[clang::fallthrough]] + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'MACRO_WITH_HISTORY;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 3333333 +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 4444444 +#undef MACRO_WITH_HISTORY +#define MACRO_WITH_HISTORY 5555555 + } + return n; +} + +template<const int N> +int fallthrough_compatibility_macro_history_template(int n) { + switch (N * n) { + case 0: + n = n * 20; +#define MACRO_WITH_HISTORY2 [[clang::fallthrough]] + case 1: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert 'MACRO_WITH_HISTORY2;' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}} + ; +#undef MACRO_WITH_HISTORY2 +#define MACRO_WITH_HISTORY2 3333333 + } + return n; +} + +#undef MACRO_WITH_HISTORY2 +#define MACRO_WITH_HISTORY2 4444444 +#undef MACRO_WITH_HISTORY2 +#define MACRO_WITH_HISTORY2 5555555 + +void f() { + fallthrough_compatibility_macro_history_template<1>(0); // expected-note{{in instantiation of function template specialization 'fallthrough_compatibility_macro_history_template<1>' requested here}} +} diff --git a/test/SemaCXX/switch-implicit-fallthrough-per-method.cpp b/test/SemaCXX/switch-implicit-fallthrough-per-method.cpp index 7c52e5138b716..009c8180b1bb8 100644 --- a/test/SemaCXX/switch-implicit-fallthrough-per-method.cpp +++ b/test/SemaCXX/switch-implicit-fallthrough-per-method.cpp @@ -42,7 +42,7 @@ void unscoped(int n) { switch (n % 2) { case 0: // FIXME: This should be typo-corrected, probably. - [[fallthrough]]; + [[fallthrough]]; // expected-warning{{unknown attribute 'fallthrough' ignored}} case 2: // expected-warning{{unannotated fall-through}} expected-note{{clang::fallthrough}} expected-note{{break;}} [[clang::fallthrough]]; case 1: diff --git a/test/SemaCXX/tag-ambig.cpp b/test/SemaCXX/tag-ambig.cpp index 6403cf30597dd..bbd17e7fe9b57 100644 --- a/test/SemaCXX/tag-ambig.cpp +++ b/test/SemaCXX/tag-ambig.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics // <rdar://problem/9168556> typedef struct Point Point; diff --git a/test/SemaCXX/trailing-return-0x.cpp b/test/SemaCXX/trailing-return-0x.cpp index c219b77d9e4d5..462b4fa3da099 100644 --- a/test/SemaCXX/trailing-return-0x.cpp +++ b/test/SemaCXX/trailing-return-0x.cpp @@ -69,3 +69,19 @@ X<int> xx; only<int> p2 = xx.f(0L); only<double> p3 = xx.g(0L, 1.0); only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f); + +namespace PR12053 { + template <typename T> + auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}} + + void test_f1() { + f1(0); // expected-error{{no matching function for call to 'f1'}} + } + + template <typename T> + auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}} + + void test_f2() { + f2(0); // expected-error{{no matching function for call to 'f2'}} + } +} diff --git a/test/SemaCXX/trivial-constructor.cpp b/test/SemaCXX/trivial-constructor.cpp index bda206b61f9a6..ed5b526a124d8 100644 --- a/test/SemaCXX/trivial-constructor.cpp +++ b/test/SemaCXX/trivial-constructor.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics struct T1 { }; static_assert(__has_trivial_constructor(T1), "T1 has trivial constructor!"); diff --git a/test/SemaCXX/trivial-destructor.cpp b/test/SemaCXX/trivial-destructor.cpp index db415cf9050a8..d3acec6284f5d 100644 --- a/test/SemaCXX/trivial-destructor.cpp +++ b/test/SemaCXX/trivial-destructor.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 +// expected-no-diagnostics struct T1 { }; static_assert(__has_trivial_destructor(T1), "T1 has trivial destructor!"); diff --git a/test/SemaCXX/typo-correction.cpp b/test/SemaCXX/typo-correction.cpp index 893f08a422ca5..c21ef51a7da59 100644 --- a/test/SemaCXX/typo-correction.cpp +++ b/test/SemaCXX/typo-correction.cpp @@ -116,14 +116,14 @@ void TestRedecl::add_in(int i) {} // expected-error{{out-of-line definition of ' // Test the improved typo correction for the Parser::ParseCastExpr => // Sema::ActOnIdExpression => Sema::DiagnoseEmptyLookup call path. -class SomeNetMessage; +class SomeNetMessage; // expected-note 2{{'SomeNetMessage'}} class Message {}; void foo(Message&); void foo(SomeNetMessage&); void doit(void *data) { Message somenetmsg; // expected-note{{'somenetmsg' declared here}} foo(somenetmessage); // expected-error{{use of undeclared identifier 'somenetmessage'; did you mean 'somenetmsg'?}} - foo((somenetmessage)data); // expected-error{{use of undeclared identifier 'somenetmessage'; did you mean 'SomeNetMessage'?}} + foo((somenetmessage)data); // expected-error{{unknown type name 'somenetmessage'; did you mean 'SomeNetMessage'?}} expected-error{{incomplete type}} } // Test the typo-correction callback in BuildRecoveryCallExpr. @@ -155,7 +155,7 @@ void Test3() { struct R {}; bool begun(R); void RangeTest() { - for (auto b : R()) {} // expected-error {{use of undeclared identifier 'begin'}} expected-note {{range has type}} + for (auto b : R()) {} // expected-error {{invalid range expression of type 'R'}} } // PR 12019 - Avoid infinite mutual recursion in DiagnoseInvalidRedeclaration @@ -172,7 +172,7 @@ void Child::add_types(int value) {} // expected-error{{out-of-line definition of // Sema::ActOnIdExpression by Parser::ParseCastExpression to allow type names as // potential corrections for template arguments. namespace clash { -class ConstructExpr {}; // expected-note{{'clash::ConstructExpr' declared here}} +class ConstructExpr {}; // expected-note 2{{'clash::ConstructExpr' declared here}} } class ClashTool { bool HaveConstructExpr(); @@ -180,7 +180,7 @@ class ClashTool { void test() { ConstructExpr *expr = // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}} - getExprAs<ConstructExpr>(); // expected-error{{use of undeclared identifier 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}} + getExprAs<ConstructExpr>(); // expected-error{{unknown type name 'ConstructExpr'; did you mean 'clash::ConstructExpr'?}} } }; @@ -220,6 +220,8 @@ namespace PR13051 { } } +inf f(doulbe); // expected-error{{'int'}} expected-error{{'double'}} + namespace PR6325 { class foo { }; // expected-note{{'foo' declared here}} // Note that for this example (pulled from the PR), if keywords are not excluded diff --git a/test/SemaCXX/uninitialized.cpp b/test/SemaCXX/uninitialized.cpp index 385548b51cca6..f55f10f7edaaa 100644 --- a/test/SemaCXX/uninitialized.cpp +++ b/test/SemaCXX/uninitialized.cpp @@ -114,6 +114,19 @@ void setupA(bool x) { A a17(a17.get2()); // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}} A a18 = x ? a18 : a17; // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}} A a19 = getA(x ? a19 : a17); // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}} + A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}} + A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}} + + // FIXME: Make the local uninitialized warning consistant with the global + // uninitialized checking. + A *a22 = new A(a22->count); // expected-warning {{variable 'a22' is uninitialized when used within its own initialization}} + A *a23 = new A(a23->ONE); // expected-warning {{variable 'a23' is uninitialized when used within its own initialization}} + A *a24 = new A(a24->TWO); // expected-warning {{variable 'a24' is uninitialized when used within its own initialization}} + A *a25 = new A(a25->zero()); // expected-warning {{variable 'a25' is uninitialized when used within its own initialization}} + + A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}} + A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}} + A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}} } bool x; @@ -138,6 +151,17 @@ A a16(&a16.num); // expected-warning {{variable 'a16' is uninitialized when use A a17(a17.get2()); // expected-warning {{variable 'a17' is uninitialized when used within its own initialization}} A a18 = x ? a18 : a17; // expected-warning {{variable 'a18' is uninitialized when used within its own initialization}} A a19 = getA(x ? a19 : a17); // expected-warning {{variable 'a19' is uninitialized when used within its own initialization}} +A a20{a20}; // expected-warning {{variable 'a20' is uninitialized when used within its own initialization}} +A a21 = {a21}; // expected-warning {{variable 'a21' is uninitialized when used within its own initialization}} + +A *a22 = new A(a22->count); +A *a23 = new A(a23->ONE); +A *a24 = new A(a24->TWO); +A *a25 = new A(a25->zero()); + +A *a26 = new A(a26->get()); // expected-warning {{variable 'a26' is uninitialized when used within its own initialization}} +A *a27 = new A(a27->get2()); // expected-warning {{variable 'a27' is uninitialized when used within its own initialization}} +A *a28 = new A(a28->num); // expected-warning {{variable 'a28' is uninitialized when used within its own initialization}} struct B { // POD struct. @@ -150,6 +174,11 @@ B getB(int x) { return B(); }; B getB(int *x) { return B(); }; B getB(B *b) { return B(); }; +B* getPtrB() { return 0; }; +B* getPtrB(int x) { return 0; }; +B* getPtrB(int *x) { return 0; }; +B* getPtrB(B **b) { return 0; }; + void setupB() { B b1; B b2(b1); @@ -166,18 +195,56 @@ void setupB() { B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}} B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}} B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}} + + B* b11 = 0; + B* b12(b11); + B* b13 = getPtrB(); + B* b14 = getPtrB(&b14); + + (void) b12; + (void) b13; + + B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}} + B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}} + + B b17 = { b17.x = 5, b17.y = 0 }; + B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}} } +B b1; +B b2(b1); +B b3 = { 5, &b3.x }; +B b4 = getB(); +B b5 = getB(&b5); +B b6 = getB(&b6.x); + +B b7(b7); // expected-warning {{variable 'b7' is uninitialized when used within its own initialization}} +B b8 = getB(b8.x); // expected-warning {{variable 'b8' is uninitialized when used within its own initialization}} +B b9 = getB(b9.y); // expected-warning {{variable 'b9' is uninitialized when used within its own initialization}} +B b10 = getB(-b10.x); // expected-warning {{variable 'b10' is uninitialized when used within its own initialization}} + +B* b11 = 0; +B* b12(b11); +B* b13 = getPtrB(); +B* b14 = getPtrB(&b14); + +B* b15 = getPtrB(b15->x); // expected-warning {{variable 'b15' is uninitialized when used within its own initialization}} +B* b16 = getPtrB(b16->y); // expected-warning {{variable 'b16' is uninitialized when used within its own initialization}} + +B b17 = { b17.x = 5, b17.y = 0 }; +B b18 = { b18.x + 1, b18.y }; // expected-warning 2{{variable 'b18' is uninitialized when used within its own initialization}} + + // Also test similar constructs in a field's initializer. struct S { int x; void *ptr; - S(bool (*)[1]) : x(x) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field is uninitialized when used here}} - S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field is uninitialized when used here}} - S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field is uninitialized when used here}} + S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[2]) : x(x + 1) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[3]) : x(x + x) {} // expected-warning 2{{field 'x' is uninitialized when used here}} + S(bool (*)[4]) : x(static_cast<long>(x) + 1) {} // expected-warning {{field 'x' is uninitialized when used here}} + S(bool (*)[5]) : x(foo(x)) {} // expected-warning {{field 'x' is uninitialized when used here}} // These don't actually require the value of x and so shouldn't warn. S(char (*)[1]) : x(sizeof(x)) {} // rdar://8610363 @@ -262,8 +329,8 @@ namespace { C c; D(char (*)[1]) : c(c.b.a.A1) {} D(char (*)[2]) : c(c.b.a.A2()) {} - D(char (*)[3]) : c(c.b.a.A3) {} // expected-warning {{field is uninitialized when used here}} - D(char (*)[4]) : c(c.b.a.A4()) {} // expected-warning {{field is uninitialized when used here}} + D(char (*)[3]) : c(c.b.a.A3) {} // expected-warning {{field 'c' is uninitialized when used here}} + D(char (*)[4]) : c(c.b.a.A4()) {} // expected-warning {{field 'c' is uninitialized when used here}} // c::a is static, so it is already initialized D(char (*)[5]) : c(c.a.A1) {} @@ -274,21 +341,21 @@ namespace { struct E { int a, b, c; - E(char (*)[1]) : a(a ? b : c) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[1]) : a(a ? b : c) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[2]) : a(b ? a : a) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[3]) : a(b ? (a) : c) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[4]) : a(b ? c : (a+c)) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[5]) : a(b ? c : b) {} - E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[6]) : a(a ?: a) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[7]) : a(b ?: a) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[8]) : a(a ?: c) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[9]) : a(b ?: c) {} E(char (*)[10]) : a((a, a, b)) {} - E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field is uninitialized when used here}} - E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field is uninitialized when used here}} - E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field is uninitialized when used here}} + E(char (*)[11]) : a((c + a, a + 1, b)) {} // expected-warning 2{{field 'a' is uninitialized when used here}} + E(char (*)[12]) : a((b + c, c, a)) {} // expected-warning {{field 'a' is uninitialized when used here}} + E(char (*)[13]) : a((a, a, a, a)) {} // expected-warning {{field 'a' is uninitialized when used here}} E(char (*)[14]) : a((b, c, c)) {} }; @@ -304,16 +371,16 @@ namespace { struct G { F f1, f2; F *f3, *f4; - G(char (*)[1]) : f1(f1) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[1]) : f1(f1) {} // expected-warning {{field 'f1' is uninitialized when used here}} G(char (*)[2]) : f2(f1) {} G(char (*)[3]) : f2(F()) {} - G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[4]) : f1(f1.*ptr) {} // expected-warning {{field 'f1' is uninitialized when used here}} G(char (*)[5]) : f2(f1.*ptr) {} - G(char (*)[6]) : f3(f3) {} // expected-warning {{field is uninitialized when used here}} - G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field is uninitialized when used here}} - G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field is uninitialized when used here}} + G(char (*)[6]) : f3(f3) {} // expected-warning {{field 'f3' is uninitialized when used here}} + G(char (*)[7]) : f3(f3->*f_ptr) {} // expected-warning {{field 'f3' is uninitialized when used here}} + G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field 'f3' is uninitialized when used here}} }; } @@ -379,21 +446,53 @@ namespace statics { } } +namespace in_class_initializers { + struct S { + S() : a(a + 1) {} // expected-warning{{field 'a' is uninitialized when used here}} + int a = 42; // Note: because a is in a member initializer list, this initialization is ignored. + }; + + struct T { + T() : b(a + 1) {} // No-warning. + int a = 42; + int b; + }; + + struct U { + U() : a(b + 1), b(a + 1) {} // FIXME: Warn here. + int a = 42; // Note: because a and b are in the member initializer list, these initializers are ignored. + int b = 1; + }; +} + namespace references { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} + int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}} + int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}} + int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}} struct S { - S() : a(a) {} // expected-warning{{field is uninitialized when used here}} + S() : a(a) {} // expected-warning{{reference 'a' is not yet bound to a value when used here}} int &a; }; void f() { - int &a = a; // expected-warning{{variable 'a' is uninitialized when used within its own initialization}} + int &a = a; // expected-warning{{reference 'a' is not yet bound to a value when used within its own initialization}} + int &b(b); // expected-warning{{reference 'b' is not yet bound to a value when used within its own initialization}} + int &c = a ? b : c; // expected-warning{{reference 'c' is not yet bound to a value when used within its own initialization}} + int &d{d}; // expected-warning{{reference 'd' is not yet bound to a value when used within its own initialization}} } struct T { T() : a(b), b(a) {} // FIXME: Warn here. int &a, &b; - int &c = c; // FIXME: Warn here. + int &c = c; // expected-warning{{reference 'c' is not yet bound to a value when used here}} + }; + + int x; + struct U { + U() : b(a) {} // No-warning. + int &a = x; + int &b; }; } diff --git a/test/SemaCXX/unknown-type-name.cpp b/test/SemaCXX/unknown-type-name.cpp index 893e0cc5dc860..ce5972bf2dc50 100644 --- a/test/SemaCXX/unknown-type-name.cpp +++ b/test/SemaCXX/unknown-type-name.cpp @@ -6,6 +6,8 @@ namespace N { }; typedef Wibble foo; + + int zeppelin; // expected-note{{declared here}} } using namespace N; @@ -15,6 +17,13 @@ void f() { foo::bar = 4; // expected-error{{no member named 'bar' in 'N::Wibble'}} } +int f(foo::bar); // expected-error{{no type named 'bar' in 'N::Wibble'}} + +int f(doulbe); // expected-error{{did you mean 'double'?}} + +int fun(zapotron); // expected-error{{unknown type name 'zapotron'}} +int var(zepelin); // expected-error{{did you mean 'zeppelin'?}} + template<typename T> struct A { typedef T type; @@ -59,6 +68,20 @@ void f(int, T::type, int) { } // expected-error{{missing 'typename'}} template<typename T> void f(int, T::type x, char) { } // expected-error{{missing 'typename'}} +int *p; + +// FIXME: We should assume that 'undeclared' is a type, not a parameter name +// here, and produce an 'unknown type name' diagnostic instead. +int f1(undeclared, int); // expected-error{{requires a type specifier}} + +int f2(undeclared, 0); // expected-error{{undeclared identifier}} + +int f3(undeclared *p, int); // expected-error{{unknown type name 'undeclared'}} + +int f4(undeclared *p, 0); // expected-error{{undeclared identifier}} + +int *test(UnknownType *fool) { return 0; } // expected-error{{unknown type name 'UnknownType'}} + template<typename T> int A<T>::n(T::value); // ok template<typename T> A<T>::type // expected-error{{missing 'typename'}} diff --git a/test/SemaCXX/unused-functions.cpp b/test/SemaCXX/unused-functions.cpp index 3598082038923..d05ff4db60559 100644 --- a/test/SemaCXX/unused-functions.cpp +++ b/test/SemaCXX/unused-functions.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wunused -verify %s +// expected-no-diagnostics static int foo(int x) { return x; } diff --git a/test/SemaCXX/unused.cpp b/test/SemaCXX/unused.cpp index 54898c828ec6e..fbaf8c8bf3c12 100644 --- a/test/SemaCXX/unused.cpp +++ b/test/SemaCXX/unused.cpp @@ -34,3 +34,30 @@ namespace derefvolatile { (void)y; // don't warn here, because it's a common pattern. } } + +// <rdar://problem/12359208> +namespace AnonObject { + struct Foo { + Foo(const char* const message); + ~Foo(); + }; + void f() { + Foo("Hello World!"); // don't warn + int(1); // expected-warning {{expression result unused}} + } +} + +// Test that constructing an object (which may have side effects) with +// constructor arguments which are dependent doesn't produce an unused value +// warning. +namespace UnresolvedLookup { + struct Foo { + Foo(int i, int j); + }; + template <typename T> + struct Bar { + void f(T t) { + Foo(t, 0); // no warning + } + }; +} diff --git a/test/SemaCXX/using-decl-pr4441.cpp b/test/SemaCXX/using-decl-pr4441.cpp index 39a446fed9acd..da21db311bb64 100644 --- a/test/SemaCXX/using-decl-pr4441.cpp +++ b/test/SemaCXX/using-decl-pr4441.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics namespace A { struct B { }; diff --git a/test/SemaCXX/using-decl-pr4450.cpp b/test/SemaCXX/using-decl-pr4450.cpp index 4f929ad15f5f4..ba81e93e0b07b 100644 --- a/test/SemaCXX/using-decl-pr4450.cpp +++ b/test/SemaCXX/using-decl-pr4450.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics namespace A { void g(); diff --git a/test/SemaCXX/value-dependent-exprs.cpp b/test/SemaCXX/value-dependent-exprs.cpp index 2017ffa67c906..b26ca253b7c08 100644 --- a/test/SemaCXX/value-dependent-exprs.cpp +++ b/test/SemaCXX/value-dependent-exprs.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -verify %s +// expected-no-diagnostics template <unsigned I> class C0 { diff --git a/test/SemaCXX/vararg-default-arg.cpp b/test/SemaCXX/vararg-default-arg.cpp index 3c8e41cb3e359..27c2bbbf5b8ee 100644 --- a/test/SemaCXX/vararg-default-arg.cpp +++ b/test/SemaCXX/vararg-default-arg.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only +// expected-no-diagnostics // PR5462 void f1(void); diff --git a/test/SemaCXX/vararg-non-pod.cpp b/test/SemaCXX/vararg-non-pod.cpp index 86b560e814c28..da06d957180e9 100644 --- a/test/SemaCXX/vararg-non-pod.cpp +++ b/test/SemaCXX/vararg-non-pod.cpp @@ -123,3 +123,21 @@ int t9(int n) { // Make sure the error works in potentially-evaluated sizeof return (int)sizeof(*(Helper(Foo()), (int (*)[n])0)); // expected-warning{{cannot pass object of non-POD type}} } + +// PR14057 +namespace t10 { + struct F { + F(); + }; + + struct S { + void operator()(F, ...); + }; + + void foo() { + S s; + F f; + s.operator()(f); + s(f); + } +} diff --git a/test/SemaCXX/vector.cpp b/test/SemaCXX/vector.cpp index 82245ac29bbd8..4d2d064b32f18 100644 --- a/test/SemaCXX/vector.cpp +++ b/test/SemaCXX/vector.cpp @@ -267,3 +267,14 @@ void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, flte4 m) { (void)(n *= m); (void)(n /= m); } + +template<typename T> void test_pseudo_dtor_tmpl(T *ptr) { + ptr->~T(); + (*ptr).~T(); +} + +void test_pseudo_dtor(fltx4 *f) { + f->~fltx4(); + (*f).~fltx4(); + test_pseudo_dtor_tmpl(f); +} diff --git a/test/SemaCXX/warn-assignment-condition.cpp b/test/SemaCXX/warn-assignment-condition.cpp index 04f2e79525475..09084e36bb491 100644 --- a/test/SemaCXX/warn-assignment-condition.cpp +++ b/test/SemaCXX/warn-assignment-condition.cpp @@ -133,14 +133,14 @@ void test2() { namespace rdar9027658 { template <typename T> -void f() { - if ((T::g == 3)) { } // expected-warning {{equality comparison with extraneous parentheses}} \ +void f(T t) { + if ((t.g == 3)) { } // expected-warning {{equality comparison with extraneous parentheses}} \ // expected-note {{use '=' to turn this equality comparison into an assignment}} \ // expected-note {{remove extraneous parentheses around the comparison to silence this warning}} } struct S { int g; }; void test() { - f<S>(); // expected-note {{in instantiation}} + f(S()); // expected-note {{in instantiation}} } } diff --git a/test/SemaCXX/warn-c++11-extensions.cpp b/test/SemaCXX/warn-c++11-extensions.cpp new file mode 100644 index 0000000000000..8f351711195eb --- /dev/null +++ b/test/SemaCXX/warn-c++11-extensions.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-extensions -verify %s + +long long ll1 = // expected-warning {{'long long' is a C++11 extension}} + -42LL; // expected-warning {{'long long' is a C++11 extension}} +unsigned long long ull1 = // expected-warning {{'long long' is a C++11 extension}} + 42ULL; // expected-warning {{'long long' is a C++11 extension}} + diff --git a/test/SemaCXX/warn-enum-compare.cpp b/test/SemaCXX/warn-enum-compare.cpp index 52639e70a8040..c68275e1a73e2 100644 --- a/test/SemaCXX/warn-enum-compare.cpp +++ b/test/SemaCXX/warn-enum-compare.cpp @@ -39,8 +39,8 @@ void test () { while (b == c); while (B1 == name1::B2); while (B2 == name2::B1); - while (x == AnonAA); - while (AnonBB == y); + while (x == AnonAA); // expected-warning {{comparison of constant 42 with expression of type 'Foo' is always false}} + while (AnonBB == y); // expected-warning {{comparison of constant 45 with expression of type 'Bar' is always false}} while (AnonAA == AnonAB); while (AnonAB == AnonBA); while (AnonBB == AnonAA); diff --git a/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp b/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp new file mode 100644 index 0000000000000..1d8037aceb730 --- /dev/null +++ b/test/SemaCXX/warn-implicit-conversion-floating-point-to-bool.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s + +float foof(float x); +double food(double x); +void foo(bool b, float f); + +void bar() { + + float c = 1.7; + bool b = c; + + double e = 1.7; + b = e; + + b = foof(4.0); + + b = foof(c < 1); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}} + + b = food(e < 2); // expected-warning {{implicit conversion turns floating-point number into bool: 'double' to 'bool'}} + + foo(c, b); // expected-warning {{implicit conversion turns floating-point number into bool: 'float' to 'bool'}} + foo(c, c); + +} diff --git a/test/SemaCXX/warn-missing-variable-declarations.cpp b/test/SemaCXX/warn-missing-variable-declarations.cpp new file mode 100644 index 0000000000000..12af9735d1a9b --- /dev/null +++ b/test/SemaCXX/warn-missing-variable-declarations.cpp @@ -0,0 +1,43 @@ +// RUN: %clang -Wmissing-variable-declarations -fsyntax-only -Xclang -verify %s + +// Variable declarations that should trigger a warning. +int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}} +int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}} + +namespace x { + int vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}} +} + +// Variable declarations that should not trigger a warning. +static int vgood1; +extern int vgood2; +int vgood2; +static struct { + int mgood1; +} vgood3; + +// Functions should never trigger a warning. +void fgood1(void); +void fgood2(void) { + int lgood1; + static int lgood2; +} +static void fgood3(void) { + int lgood3; + static int lgood4; +} + +// Structures, namespaces and classes should be unaffected. +struct sgood1 { + int mgood2; +}; +struct { + int mgood3; +} sgood2; +class CGood1 { + static int MGood1; +}; +int CGood1::MGood1; +namespace { + int mgood4; +} diff --git a/test/SemaCXX/warn-new-overaligned-2.cpp b/test/SemaCXX/warn-new-overaligned-2.cpp index 550500906892b..e643015f31b80 100644 --- a/test/SemaCXX/warn-new-overaligned-2.cpp +++ b/test/SemaCXX/warn-new-overaligned-2.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -triple=x86_64-pc-linux-gnu -Wover-aligned -verify %s +// expected-no-diagnostics // This test verifies that we don't warn when the global operator new is // overridden. That's why we can't merge this with the other test file. diff --git a/test/SemaCXX/warn-overloaded-virtual.cpp b/test/SemaCXX/warn-overloaded-virtual.cpp index 8e2b671bf4936..9b0f5aa9f339e 100644 --- a/test/SemaCXX/warn-overloaded-virtual.cpp +++ b/test/SemaCXX/warn-overloaded-virtual.cpp @@ -64,3 +64,59 @@ public: static void f() {} }; } + +namespace ThreeLayer { +struct A { + virtual void f(); +}; + +struct B: A { + void f(); + void f(int); +}; + +struct C: B { + void f(int); + using A::f; +}; +} + +namespace UnbalancedVirtual { +struct Base { + virtual void func(); +}; + +struct Derived1: virtual Base { + virtual void func(); +}; + +struct Derived2: virtual Base { +}; + +struct MostDerived: Derived1, Derived2 { + void func(int); + void func(); +}; +} + +namespace UnbalancedVirtual2 { +struct Base { + virtual void func(); +}; + +struct Derived1: virtual Base { + virtual void func(); +}; + +struct Derived2: virtual Base { +}; + +struct Derived3: Derived1 { + virtual void func(); +}; + +struct MostDerived: Derived3, Derived2 { + void func(int); + void func(); +}; +} diff --git a/test/SemaCXX/warn-self-comparisons.cpp b/test/SemaCXX/warn-self-comparisons.cpp index 620be195c1de0..2e8d130bcd5a0 100644 --- a/test/SemaCXX/warn-self-comparisons.cpp +++ b/test/SemaCXX/warn-self-comparisons.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics void f(int (&array1)[2], int (&array2)[2]) { if (array1 == array2) { } // no warning diff --git a/test/SemaCXX/warn-thread-safety-analysis.cpp b/test/SemaCXX/warn-thread-safety-analysis.cpp index 17a1931c15949..bd555ac56c363 100644 --- a/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -24,10 +24,6 @@ __attribute__ ((shared_locks_required(__VA_ARGS__))) #define NO_THREAD_SAFETY_ANALYSIS __attribute__ ((no_thread_safety_analysis)) -//-----------------------------------------// -// Helper fields -//-----------------------------------------// - class __attribute__((lockable)) Mutex { public: @@ -60,6 +56,15 @@ class SCOPED_LOCKABLE ReleasableMutexLock { }; +// The universal lock, written "*", allows checking to be selectively turned +// off for a particular piece of code. +void beginNoWarnOnReads() SHARED_LOCK_FUNCTION("*"); +void endNoWarnOnReads() UNLOCK_FUNCTION("*"); +void beginNoWarnOnWrites() EXCLUSIVE_LOCK_FUNCTION("*"); +void endNoWarnOnWrites() UNLOCK_FUNCTION("*"); + + +// For testing handling of smart pointers. template<class T> class SmartPtr { public: @@ -76,6 +81,15 @@ private: }; +// For testing destructor calls and cleanup. +class MyString { +public: + MyString(const char* s); + ~MyString(); +}; + + + Mutex sls_mu; Mutex sls_mu2 __attribute__((acquired_after(sls_mu))); @@ -529,7 +543,8 @@ void late_bad_0() { LateFoo fooB; fooA.mu.Lock(); fooB.a = 5; // \ - // expected-warning{{writing variable 'a' requires locking 'fooB.mu' exclusively}} + // expected-warning{{writing variable 'a' requires locking 'fooB.mu' exclusively}} \ + // expected-note{{found near match 'fooA.mu'}} fooA.mu.Unlock(); } @@ -549,7 +564,8 @@ void late_bad_2() { LateBar BarA; BarA.FooPointer->mu.Lock(); BarA.Foo.a = 2; // \ - // expected-warning{{writing variable 'a' requires locking 'BarA.Foo.mu' exclusively}} + // expected-warning{{writing variable 'a' requires locking 'BarA.Foo.mu' exclusively}} \ + // expected-note{{found near match 'BarA.FooPointer->mu'}} BarA.FooPointer->mu.Unlock(); } @@ -557,7 +573,8 @@ void late_bad_3() { LateBar BarA; BarA.Foo.mu.Lock(); BarA.FooPointer->a = 2; // \ - // expected-warning{{writing variable 'a' requires locking 'BarA.FooPointer->mu' exclusively}} + // expected-warning{{writing variable 'a' requires locking 'BarA.FooPointer->mu' exclusively}} \ + // expected-note{{found near match 'BarA.Foo.mu'}} BarA.Foo.mu.Unlock(); } @@ -565,7 +582,8 @@ void late_bad_4() { LateBar BarA; BarA.Foo.mu.Lock(); BarA.Foo2.a = 2; // \ - // expected-warning{{writing variable 'a' requires locking 'BarA.Foo2.mu' exclusively}} + // expected-warning{{writing variable 'a' requires locking 'BarA.Foo2.mu' exclusively}} \ + // expected-note{{found near match 'BarA.Foo.mu'}} BarA.Foo.mu.Unlock(); } @@ -1233,7 +1251,9 @@ void func() { b1->MyLock(); b1->a_ = 5; - b2->a_ = 3; // expected-warning {{writing variable 'a_' requires locking 'b2->mu1_' exclusively}} + b2->a_ = 3; // \ + // expected-warning {{writing variable 'a_' requires locking 'b2->mu1_' exclusively}} \ + // expected-note {{found near match 'b1->mu1_'}} b2->MyLock(); b2->MyUnlock(); b1->MyUnlock(); @@ -1263,11 +1283,13 @@ int func(int i) int x; b3->mu1_.Lock(); res = b1.a_ + b3->b_; // expected-warning {{reading variable 'a_' requires locking 'b1.mu1_'}} \ - // expected-warning {{writing variable 'res' requires locking 'mu' exclusively}} + // expected-warning {{writing variable 'res' requires locking 'mu' exclusively}} \ + // expected-note {{found near match 'b3->mu1_'}} *p = i; // expected-warning {{reading variable 'p' requires locking 'mu'}} \ // expected-warning {{writing the value pointed to by 'p' requires locking 'mu' exclusively}} b1.a_ = res + b3->b_; // expected-warning {{reading variable 'res' requires locking 'mu'}} \ - // expected-warning {{writing variable 'a_' requires locking 'b1.mu1_' exclusively}} + // expected-warning {{writing variable 'a_' requires locking 'b1.mu1_' exclusively}} \ + // expected-note {{found near match 'b3->mu1_'}} b3->b_ = *b1.q; // expected-warning {{reading the value pointed to by 'q' requires locking 'mu'}} b3->mu1_.Unlock(); b1.b_ = res; // expected-warning {{reading variable 'res' requires locking 'mu'}} @@ -1292,8 +1314,12 @@ class Foo { child->Func(new_foo); // There shouldn't be any warning here as the // acquired lock is not in child. - child->bar(7); // expected-warning {{calling function 'bar' requires exclusive lock on 'child->lock_'}} - child->a_ = 5; // expected-warning {{writing variable 'a_' requires locking 'child->lock_' exclusively}} + child->bar(7); // \ + // expected-warning {{calling function 'bar' requires exclusive lock on 'child->lock_'}} \ + // expected-note {{found near match 'lock_'}} + child->a_ = 5; // \ + // expected-warning {{writing variable 'a_' requires locking 'child->lock_' exclusively}} \ + // expected-note {{found near match 'lock_'}} lock_.Unlock(); } @@ -1491,7 +1517,8 @@ namespace substitution_test { DataLocker dlr; dlr.lockData(d1); foo(d2); // \ - // expected-warning {{calling function 'foo' requires exclusive lock on 'd2->mu'}} + // expected-warning {{calling function 'foo' requires exclusive lock on 'd2->mu'}} \ + // expected-note {{found near match 'd1->mu'}} dlr.unlockData(d1); } }; @@ -1516,22 +1543,6 @@ namespace constructor_destructor_tests { } -namespace invalid_lock_expression_test { - -class LOCKABLE MyLockable { -public: - MyLockable() __attribute__((exclusive_lock_function)) { } - ~MyLockable() { } -}; - -// create an empty lock expression -void foo() { - MyLockable lock; // \ - // expected-warning {{cannot resolve lock expression}} -} - -} // end namespace invalid_lock_expression_test - namespace template_member_test { struct S { int n; }; @@ -1638,6 +1649,8 @@ void bar() { }; // end namespace FunctionAttrTest +namespace TryLockTest { + struct TestTryLock { Mutex mu; int a GUARDED_BY(mu); @@ -1734,8 +1747,36 @@ struct TestTryLock { b = !b; } } + + // Test merge of exclusive trylock + void foo11() { + if (cond) { + if (!mu.TryLock()) + return; + } + else { + mu.Lock(); + } + a = 10; + mu.Unlock(); + } + + // Test merge of shared trylock + void foo12() { + if (cond) { + if (!mu.ReaderTryLock()) + return; + } + else { + mu.ReaderLock(); + } + int i = a; + mu.Unlock(); + } }; // end TestTrylock +} // end namespace TrylockTest + namespace TestTemplateAttributeInstantiation { @@ -1829,7 +1870,8 @@ void test() { f1.mu_.Unlock(); bt.barTD(&f1); // \ - // expected-warning {{calling function 'barTD' requires exclusive lock on 'f1.mu_'}} + // expected-warning {{calling function 'barTD' requires exclusive lock on 'f1.mu_'}} \ + // expected-note {{found near match 'bt.fooBase.mu_'}} bt.fooBase.mu_.Unlock(); bt.fooBaseT.mu_.Unlock(); @@ -2235,27 +2277,32 @@ void test() { bar.getFoo().mu_.Lock(); bar.getFooey().a = 0; // \ - // expected-warning {{writing variable 'a' requires locking 'bar.getFooey().mu_' exclusively}} + // expected-warning {{writing variable 'a' requires locking 'bar.getFooey().mu_' exclusively}} \ + // expected-note {{found near match 'bar.getFoo().mu_'}} bar.getFoo().mu_.Unlock(); bar.getFoo2(a).mu_.Lock(); bar.getFoo2(b).a = 0; // \ - // expected-warning {{writing variable 'a' requires locking 'bar.getFoo2(b).mu_' exclusively}} + // expected-warning {{writing variable 'a' requires locking 'bar.getFoo2(b).mu_' exclusively}} \ + // expected-note {{found near match 'bar.getFoo2(a).mu_'}} bar.getFoo2(a).mu_.Unlock(); bar.getFoo3(a, b).mu_.Lock(); bar.getFoo3(a, c).a = 0; // \ - // expected-warning {{writing variable 'a' requires locking 'bar.getFoo3(a,c).mu_' exclusively}} + // expected-warning {{writing variable 'a' requires locking 'bar.getFoo3(a,c).mu_' exclusively}} \ + // expected-note {{'bar.getFoo3(a,b).mu_'}} bar.getFoo3(a, b).mu_.Unlock(); getBarFoo(bar, a).mu_.Lock(); getBarFoo(bar, b).a = 0; // \ - // expected-warning {{writing variable 'a' requires locking 'getBarFoo(bar,b).mu_' exclusively}} + // expected-warning {{writing variable 'a' requires locking 'getBarFoo(bar,b).mu_' exclusively}} \ + // expected-note {{'getBarFoo(bar,a).mu_'}} getBarFoo(bar, a).mu_.Unlock(); (a > 0 ? fooArray[1] : fooArray[b]).mu_.Lock(); (a > 0 ? fooArray[b] : fooArray[c]).a = 0; // \ - // expected-warning {{writing variable 'a' requires locking '((a#_)#_#fooArray[b]).mu_' exclusively}} + // expected-warning {{writing variable 'a' requires locking '((a#_)#_#fooArray[b]).mu_' exclusively}} \ + // expected-note {{'((a#_)#_#fooArray[_]).mu_'}} (a > 0 ? fooArray[1] : fooArray[b]).mu_.Unlock(); } @@ -2314,7 +2361,9 @@ void test1(Foo* f1, Foo* f2) { f1->a = 0; f1->foo(); - f1->foo2(f2); // expected-warning {{calling function 'foo2' requires exclusive lock on 'f2->mu_'}} + f1->foo2(f2); // \ + // expected-warning {{calling function 'foo2' requires exclusive lock on 'f2->mu_'}} \ + // expected-note {{found near match 'f1->mu_'}} Foo::getMu(f2)->Lock(); f1->foo2(f2); @@ -2354,7 +2403,9 @@ void test2(Bar* b1, Bar* b2) { b1->b = 0; b1->bar(); - b1->bar2(b2); // expected-warning {{calling function 'bar2' requires exclusive lock on 'b2->mu_'}} + b1->bar2(b2); // \ + // expected-warning {{calling function 'bar2' requires exclusive lock on 'b2->mu_'}} \ + // // expected-note {{found near match 'b1->mu_'}} b2->getMu()->Lock(); b1->bar2(b2); @@ -3119,3 +3170,545 @@ void test() { } // end namespace ExistentialPatternMatching + +namespace StringIgnoreTest { + +class Foo { +public: + Mutex mu_; + void lock() EXCLUSIVE_LOCK_FUNCTION(""); + void unlock() UNLOCK_FUNCTION(""); + void goober() EXCLUSIVE_LOCKS_REQUIRED(""); + void roober() SHARED_LOCKS_REQUIRED(""); +}; + + +class Bar : public Foo { +public: + void bar(Foo* f) { + f->unlock(); + f->goober(); + f->roober(); + f->lock(); + }; +}; + +} // end namespace StringIgnoreTest + + +namespace LockReturnedScopeFix { + +class Base { +protected: + struct Inner; + bool c; + + const Mutex& getLock(const Inner* i); + + void lockInner (Inner* i) EXCLUSIVE_LOCK_FUNCTION(getLock(i)); + void unlockInner(Inner* i) UNLOCK_FUNCTION(getLock(i)); + void foo(Inner* i) EXCLUSIVE_LOCKS_REQUIRED(getLock(i)); + + void bar(Inner* i); +}; + + +struct Base::Inner { + Mutex lock_; + void doSomething() EXCLUSIVE_LOCKS_REQUIRED(lock_); +}; + + +const Mutex& Base::getLock(const Inner* i) LOCK_RETURNED(i->lock_) { + return i->lock_; +} + + +void Base::foo(Inner* i) { + i->doSomething(); +} + +void Base::bar(Inner* i) { + if (c) { + i->lock_.Lock(); + unlockInner(i); + } + else { + lockInner(i); + i->lock_.Unlock(); + } +} + +} // end namespace LockReturnedScopeFix + + +namespace TrylockWithCleanups { + +struct Foo { + Mutex mu_; + int a GUARDED_BY(mu_); +}; + +Foo* GetAndLockFoo(const MyString& s) + EXCLUSIVE_TRYLOCK_FUNCTION(true, &Foo::mu_); + +static void test() { + Foo* lt = GetAndLockFoo("foo"); + if (!lt) return; + int a = lt->a; + lt->mu_.Unlock(); +} + +} // end namespace TrylockWithCleanups + + +namespace UniversalLock { + +class Foo { + Mutex mu_; + bool c; + + int a GUARDED_BY(mu_); + void r_foo() SHARED_LOCKS_REQUIRED(mu_); + void w_foo() EXCLUSIVE_LOCKS_REQUIRED(mu_); + + void test1() { + int b; + + beginNoWarnOnReads(); + b = a; + r_foo(); + endNoWarnOnReads(); + + beginNoWarnOnWrites(); + a = 0; + w_foo(); + endNoWarnOnWrites(); + } + + // don't warn on joins with universal lock + void test2() { + if (c) { + beginNoWarnOnWrites(); + } + a = 0; // \ + // expected-warning {{writing variable 'a' requires locking 'mu_' exclusively}} + endNoWarnOnWrites(); // \ + // expected-warning {{unlocking '*' that was not locked}} + } + + + // make sure the universal lock joins properly + void test3() { + if (c) { + mu_.Lock(); + beginNoWarnOnWrites(); + } + else { + beginNoWarnOnWrites(); + mu_.Lock(); + } + a = 0; + endNoWarnOnWrites(); + mu_.Unlock(); + } + + + // combine universal lock with other locks + void test4() { + beginNoWarnOnWrites(); + mu_.Lock(); + mu_.Unlock(); + endNoWarnOnWrites(); + + mu_.Lock(); + beginNoWarnOnWrites(); + endNoWarnOnWrites(); + mu_.Unlock(); + + mu_.Lock(); + beginNoWarnOnWrites(); + mu_.Unlock(); + endNoWarnOnWrites(); + } +}; + +} // end namespace UniversalLock + + +namespace TemplateLockReturned { + +template<class T> +class BaseT { +public: + virtual void baseMethod() = 0; + Mutex* get_mutex() LOCK_RETURNED(mutex_) { return &mutex_; } + + Mutex mutex_; + int a GUARDED_BY(mutex_); +}; + + +class Derived : public BaseT<int> { +public: + void baseMethod() EXCLUSIVE_LOCKS_REQUIRED(get_mutex()) { + a = 0; + } +}; + +} // end namespace TemplateLockReturned + + +namespace ExprMatchingBugFix { + +class Foo { +public: + Mutex mu_; +}; + + +class Bar { +public: + bool c; + Foo* foo; + Bar(Foo* f) : foo(f) { } + + struct Nested { + Foo* foo; + Nested(Foo* f) : foo(f) { } + + void unlockFoo() UNLOCK_FUNCTION(&Foo::mu_); + }; + + void test(); +}; + + +void Bar::test() { + foo->mu_.Lock(); + if (c) { + Nested *n = new Nested(foo); + n->unlockFoo(); + } + else { + foo->mu_.Unlock(); + } +} + +}; // end namespace ExprMatchingBugfix + + +namespace ComplexNameTest { + +class Foo { +public: + static Mutex mu_; + + Foo() EXCLUSIVE_LOCKS_REQUIRED(mu_) { } + ~Foo() EXCLUSIVE_LOCKS_REQUIRED(mu_) { } + + int operator[](int i) EXCLUSIVE_LOCKS_REQUIRED(mu_) { return 0; } +}; + +class Bar { +public: + static Mutex mu_; + + Bar() LOCKS_EXCLUDED(mu_) { } + ~Bar() LOCKS_EXCLUDED(mu_) { } + + int operator[](int i) LOCKS_EXCLUDED(mu_) { return 0; } +}; + + +void test1() { + Foo f; // expected-warning {{calling function 'Foo' requires exclusive lock on 'mu_'}} + int a = f[0]; // expected-warning {{calling function 'operator[]' requires exclusive lock on 'mu_'}} +} // expected-warning {{calling function '~Foo' requires exclusive lock on 'mu_'}} + + +void test2() { + Bar::mu_.Lock(); + { + Bar b; // expected-warning {{cannot call function 'Bar' while mutex 'mu_' is locked}} + int a = b[0]; // expected-warning {{cannot call function 'operator[]' while mutex 'mu_' is locked}} + } // expected-warning {{cannot call function '~Bar' while mutex 'mu_' is locked}} + Bar::mu_.Unlock(); +} + +}; // end namespace ComplexNameTest + + +namespace UnreachableExitTest { + +class FemmeFatale { +public: + FemmeFatale(); + ~FemmeFatale() __attribute__((noreturn)); +}; + +void exitNow() __attribute__((noreturn)); +void exitDestruct(const MyString& ms) __attribute__((noreturn)); + +Mutex fatalmu_; + +void test1() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) { + exitNow(); +} + +void test2() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) { + FemmeFatale femme; +} + +bool c; + +void test3() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) { + if (c) { + exitNow(); + } + else { + FemmeFatale femme; + } +} + +void test4() EXCLUSIVE_LOCKS_REQUIRED(fatalmu_) { + exitDestruct("foo"); +} + +} // end namespace UnreachableExitTest + + +namespace VirtualMethodCanonicalizationTest { + +class Base { +public: + virtual Mutex* getMutex() = 0; +}; + +class Base2 : public Base { +public: + Mutex* getMutex(); +}; + +class Base3 : public Base2 { +public: + Mutex* getMutex(); +}; + +class Derived : public Base3 { +public: + Mutex* getMutex(); // overrides Base::getMutex() +}; + +void baseFun(Base *b) EXCLUSIVE_LOCKS_REQUIRED(b->getMutex()) { } + +void derivedFun(Derived *d) EXCLUSIVE_LOCKS_REQUIRED(d->getMutex()) { + baseFun(d); +} + +} // end namespace VirtualMethodCanonicalizationTest + + +namespace TemplateFunctionParamRemapTest { + +template <class T> +struct Cell { + T dummy_; + Mutex* mu_; +}; + +class Foo { +public: + template <class T> + void elr(Cell<T>* c) __attribute__((exclusive_locks_required(c->mu_))); + + void test(); +}; + +template<class T> +void Foo::elr(Cell<T>* c1) { } + +void Foo::test() { + Cell<int> cell; + elr(&cell); // \ + // expected-warning {{calling function 'elr' requires exclusive lock on 'cell.mu_'}} +} + + +template<class T> +void globalELR(Cell<T>* c) __attribute__((exclusive_locks_required(c->mu_))); + +template<class T> +void globalELR(Cell<T>* c1) { } + +void globalTest() { + Cell<int> cell; + globalELR(&cell); // \ + // expected-warning {{calling function 'globalELR' requires exclusive lock on 'cell.mu_'}} +} + + +template<class T> +void globalELR2(Cell<T>* c) __attribute__((exclusive_locks_required(c->mu_))); + +// second declaration +template<class T> +void globalELR2(Cell<T>* c2); + +template<class T> +void globalELR2(Cell<T>* c3) { } + +// re-declaration after definition +template<class T> +void globalELR2(Cell<T>* c4); + +void globalTest2() { + Cell<int> cell; + globalELR2(&cell); // \ + // expected-warning {{calling function 'globalELR2' requires exclusive lock on 'cell.mu_'}} +} + + +template<class T> +class FooT { +public: + void elr(Cell<T>* c) __attribute__((exclusive_locks_required(c->mu_))); +}; + +template<class T> +void FooT<T>::elr(Cell<T>* c1) { } + +void testFooT() { + Cell<int> cell; + FooT<int> foo; + foo.elr(&cell); // \ + // expected-warning {{calling function 'elr' requires exclusive lock on 'cell.mu_'}} +} + +} // end namespace TemplateFunctionParamRemapTest + + +namespace SelfConstructorTest { + +class SelfLock { +public: + SelfLock() EXCLUSIVE_LOCK_FUNCTION(mu_); + ~SelfLock() UNLOCK_FUNCTION(mu_); + + void foo() EXCLUSIVE_LOCKS_REQUIRED(mu_); + + Mutex mu_; +}; + +class LOCKABLE SelfLock2 { +public: + SelfLock2() EXCLUSIVE_LOCK_FUNCTION(); + ~SelfLock2() UNLOCK_FUNCTION(); + + void foo() EXCLUSIVE_LOCKS_REQUIRED(this); +}; + + +void test() { + SelfLock s; + s.foo(); +} + +void test2() { + SelfLock2 s2; + s2.foo(); +} + +} // end namespace SelfConstructorTest + + +namespace MultipleAttributeTest { + +class Foo { + Mutex mu1_; + Mutex mu2_; + int a GUARDED_BY(mu1_); + int b GUARDED_BY(mu2_); + int c GUARDED_BY(mu1_) GUARDED_BY(mu2_); + int* d PT_GUARDED_BY(mu1_) PT_GUARDED_BY(mu2_); + + void foo1() EXCLUSIVE_LOCKS_REQUIRED(mu1_) + EXCLUSIVE_LOCKS_REQUIRED(mu2_); + void foo2() SHARED_LOCKS_REQUIRED(mu1_) + SHARED_LOCKS_REQUIRED(mu2_); + void foo3() LOCKS_EXCLUDED(mu1_) + LOCKS_EXCLUDED(mu2_); + void lock() EXCLUSIVE_LOCK_FUNCTION(mu1_) + EXCLUSIVE_LOCK_FUNCTION(mu2_); + void readerlock() EXCLUSIVE_LOCK_FUNCTION(mu1_) + EXCLUSIVE_LOCK_FUNCTION(mu2_); + void unlock() UNLOCK_FUNCTION(mu1_) + UNLOCK_FUNCTION(mu2_); + bool trylock() EXCLUSIVE_TRYLOCK_FUNCTION(true, mu1_) + EXCLUSIVE_TRYLOCK_FUNCTION(true, mu2_); + bool readertrylock() SHARED_TRYLOCK_FUNCTION(true, mu1_) + SHARED_TRYLOCK_FUNCTION(true, mu2_); + + void test(); +}; + + +void Foo::foo1() { + a = 1; + b = 2; +} + +void Foo::foo2() { + int result = a + b; +} + +void Foo::foo3() { } +void Foo::lock() { } +void Foo::readerlock() { } +void Foo::unlock() { } +bool Foo::trylock() { return true; } +bool Foo::readertrylock() { return true; } + + +void Foo::test() { + mu1_.Lock(); + foo1(); // expected-warning {{}} + c = 0; // expected-warning {{}} + *d = 0; // expected-warning {{}} + mu1_.Unlock(); + + mu1_.ReaderLock(); + foo2(); // expected-warning {{}} + int x = c; // expected-warning {{}} + int y = *d; // expected-warning {{}} + mu1_.Unlock(); + + mu2_.Lock(); + foo3(); // expected-warning {{}} + mu2_.Unlock(); + + lock(); + a = 0; + b = 0; + unlock(); + + readerlock(); + int z = a + b; + unlock(); + + if (trylock()) { + a = 0; + b = 0; + unlock(); + } + + if (readertrylock()) { + int zz = a + b; + unlock(); + } +} + + +} // end namespace MultipleAttributeTest + + diff --git a/test/SemaCXX/warn-thread-safety-parsing.cpp b/test/SemaCXX/warn-thread-safety-parsing.cpp index 8aa6a91a9d2d4..df9415cf8601a 100644 --- a/test/SemaCXX/warn-thread-safety-parsing.cpp +++ b/test/SemaCXX/warn-thread-safety-parsing.cpp @@ -1255,7 +1255,7 @@ public: void foo4(FooLate *f) EXCLUSIVE_LOCKS_REQUIRED(f->mu); static void foo5() EXCLUSIVE_LOCKS_REQUIRED(mu); // \ - // expected-error {{'this' cannot be implicitly used in a static member function declaration}} + // expected-error {{invalid use of member 'mu' in static member function}} template <class T> void foo6() EXCLUSIVE_LOCKS_REQUIRED(T::statmu) { } @@ -1440,3 +1440,50 @@ void Foo::bar(Mutex* mu) LOCKS_EXCLUDED(mu) { } // \ } // end namespace InvalidDeclTest + +namespace StaticScopeTest { + +class FooStream; + +class Foo { + mutable Mutex mu; + int a GUARDED_BY(mu); + + static int si GUARDED_BY(mu); // \ + // expected-error {{invalid use of non-static data member 'mu'}} + + static void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); // \ + // expected-error {{invalid use of member 'mu' in static member function}} + + friend FooStream& operator<<(FooStream& s, const Foo& f) + EXCLUSIVE_LOCKS_REQUIRED(mu); // \ + // expected-error {{invalid use of non-static data member 'mu'}} +}; + + +} // end namespace StaticScopeTest + + +namespace FunctionAttributesInsideClass_ICE_Test { + +class Foo { +public: + /* Originally found when parsing foo() as an ordinary method after the + * the following: + + template <class T> + void syntaxErrorMethod(int i) { + if (i) { + foo( + } + } + */ + + void method() { + void foo() EXCLUSIVE_LOCKS_REQUIRED(mu); // \ + // expected-error {{use of undeclared identifier 'mu'}} + } +}; + +} // end namespace FunctionAttributesInsideClass_ICE_Test + diff --git a/test/SemaCXX/warn-unique-enum.cpp b/test/SemaCXX/warn-unique-enum.cpp deleted file mode 100644 index 59a1278071727..0000000000000 --- a/test/SemaCXX/warn-unique-enum.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clang_cc1 %s -fsyntax-only -verify -Wunique-enum -enum A { A1 = 1, A2 = 1, A3 = 1 }; // expected-warning {{all elements of 'A' are initialized with literals to value 1}} \ -// expected-note {{initialize the last element with the previous element to silence this warning}} -enum { B1 = 1, B2 = 1, B3 = 1 }; // no warning -enum C { // expected-warning {{all elements of 'C' are initialized with literals to value 1}} - C1 = true, - C2 = true // expected-note {{initialize the last element with the previous element to silence this warning}} -}; -enum D { D1 = 5, D2 = 5L, D3 = 5UL, D4 = 5LL, D5 = 5ULL }; // expected-warning {{all elements of 'D' are initialized with literals to value 5}} \ -// expected-note {{initialize the last element with the previous element to silence this warning}} - -// Don't warn on enums with less than 2 elements. -enum E { E1 = 4 }; -enum F { F1 }; -enum G {}; - -// Don't warn when integer literals do not initialize the elements. -enum H { H1 = 4, H_MAX = H1, H_MIN = H1 }; -enum I { I1 = H1, I2 = 4 }; -enum J { J1 = 4, J2 = I2 }; -enum K { K1, K2, K3, K4 }; - -// Don't crash or warn on this one. -// rdar://11875995 -enum L { - L1 = 0x8000000000000000ULL, L2 = 0x0000000000000001ULL -}; diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp index dbff4b0e68c18..ad896b5212044 100644 --- a/test/SemaCXX/warn-unused-filescoped.cpp +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s static void f1(); // expected-warning{{unused}} @@ -87,3 +88,16 @@ namespace rdar8733476 { foo(); } } + +namespace test5 { + static int n = 0; + static int &r = n; + int f(int &); + int k = f(r); + + // FIXME: We should produce warnings for both of these. + static const int m = n; + int x = sizeof(m); + static const double d = 0.0; + int y = sizeof(d); +} diff --git a/test/SemaCXX/warn-unused-variables.cpp b/test/SemaCXX/warn-unused-variables.cpp index 582701957e594..4e8d51d319e93 100644 --- a/test/SemaCXX/warn-unused-variables.cpp +++ b/test/SemaCXX/warn-unused-variables.cpp @@ -42,10 +42,11 @@ void test_dependent_init(T *p) { } namespace PR6948 { - template<typename T> class X; + template<typename T> class X; // expected-note{{template is declared here}} void f() { - X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} + X<char> str (read_from_file()); // expected-error{{use of undeclared identifier 'read_from_file'}} \ + expected-error{{implicit instantiation of undefined template 'PR6948::X<char>'}} } } @@ -122,3 +123,15 @@ namespace PR11550 { S3 z = a; // expected-warning {{unused variable 'z'}} } } + +namespace ctor_with_cleanups { + struct S1 { + ~S1(); + }; + struct S2 { + S2(const S1&); + }; + void func() { + S2 s((S1())); + } +} diff --git a/test/SemaCXX/warn-using-namespace-in-header.cpp b/test/SemaCXX/warn-using-namespace-in-header.cpp index 72c25529b40f8..f68b99893aae7 100644 --- a/test/SemaCXX/warn-using-namespace-in-header.cpp +++ b/test/SemaCXX/warn-using-namespace-in-header.cpp @@ -1,54 +1,60 @@ // RUN: %clang_cc1 -fsyntax-only -Wheader-hygiene -verify %s -#include "warn-using-namespace-in-header.h" +#ifdef BE_THE_HEADER +namespace warn_in_header_in_global_context {} +using namespace warn_in_header_in_global_context; // expected-warning {{using namespace directive in global context in header}} + +// While we want to error on the previous using directive, we don't when we are +// inside a namespace +namespace dont_warn_here { +using namespace warn_in_header_in_global_context; +} + +// We should warn in toplevel extern contexts. +namespace warn_inside_linkage {} +extern "C++" { +using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} +} + +// This is really silly, but we should warn on it: +extern "C++" { +extern "C" { +extern "C++" { +using namespace warn_inside_linkage; // expected-warning {{using namespace directive in global context in header}} +} +} +} + +// But we shouldn't warn in extern contexts inside namespaces. +namespace dont_warn_here { +extern "C++" { +using namespace warn_in_header_in_global_context; +} +} + +// We also shouldn't warn in case of functions. +inline void foo() { + using namespace warn_in_header_in_global_context; +} + + +namespace macronamespace {} +#define USING_MACRO using namespace macronamespace; + +// |using namespace| through a macro should warn if the instantiation is in a +// header. +USING_MACRO // expected-warning {{using namespace directive in global context in header}} + +#else + +#define BE_THE_HEADER +#include __FILE__ namespace dont_warn {} using namespace dont_warn; -// Warning is actually in the header but only the cpp file gets scanned. -// expected-warning {{using namespace directive in global context in header}} - - - - - - - - - -// Warn inside linkage specs too. -// expected-warning {{using namespace directive in global context in header}} - - - - - - -// expected-warning {{using namespace directive in global context in header}} - - - - - - - - - - - - - - - - - - - - - - -// expected-warning {{using namespace directive in global context in header}} - // |using namespace| through a macro shouldn't warn if the instantiation is in a // cc file. USING_MACRO + +#endif diff --git a/test/SemaCXX/warn-using-namespace-in-header.h b/test/SemaCXX/warn-using-namespace-in-header.h deleted file mode 100644 index b544c548ae9bb..0000000000000 --- a/test/SemaCXX/warn-using-namespace-in-header.h +++ /dev/null @@ -1,50 +0,0 @@ - - - - - -// Lots of vertical space to make the error line match up with the line of the -// expected line in the source file. -namespace warn_in_header_in_global_context {} -using namespace warn_in_header_in_global_context; - -// While we want to error on the previous using directive, we don't when we are -// inside a namespace -namespace dont_warn_here { -using namespace warn_in_header_in_global_context; -} - -// We should warn in toplevel extern contexts. -namespace warn_inside_linkage {} -extern "C++" { -using namespace warn_inside_linkage; -} - -// This is really silly, but we should warn on it: -extern "C++" { -extern "C" { -extern "C++" { -using namespace warn_inside_linkage; -} -} -} - -// But we shouldn't warn in extern contexts inside namespaces. -namespace dont_warn_here { -extern "C++" { -using namespace warn_in_header_in_global_context; -} -} - -// We also shouldn't warn in case of functions. -inline void foo() { - using namespace warn_in_header_in_global_context; -} - - -namespace macronamespace {} -#define USING_MACRO using namespace macronamespace; - -// |using namespace| through a macro should warn if the instantiation is in a -// header. -USING_MACRO diff --git a/test/SemaCXX/zero-length-arrays.cpp b/test/SemaCXX/zero-length-arrays.cpp index 05ded4ad9b3c1..d86ab8666d53e 100644 --- a/test/SemaCXX/zero-length-arrays.cpp +++ b/test/SemaCXX/zero-length-arrays.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics // <rdar://problem/10228639> class Foo { |