diff options
Diffstat (limited to 'test/Lexer')
| -rw-r--r-- | test/Lexer/aligned-allocation.cpp | 23 | ||||
| -rw-r--r-- | test/Lexer/cross-windows-on-linux.cpp | 2 | ||||
| -rw-r--r-- | test/Lexer/cxx-features.cpp | 138 | ||||
| -rw-r--r-- | test/Lexer/has_feature_memory_sanitizer.cpp | 1 | ||||
| -rw-r--r-- | test/Lexer/has_feature_undefined_behavior_sanitizer.cpp | 13 | ||||
| -rw-r--r-- | test/Lexer/has_feature_xray_instrument.cpp | 11 | ||||
| -rw-r--r-- | test/Lexer/unicode.c | 12 |
7 files changed, 135 insertions, 65 deletions
diff --git a/test/Lexer/aligned-allocation.cpp b/test/Lexer/aligned-allocation.cpp new file mode 100644 index 0000000000000..eef5d980a37b8 --- /dev/null +++ b/test/Lexer/aligned-allocation.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -DEXPECT_DEFINED +// +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -faligned-alloc-unavailable +// +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \ +// RUN: -faligned-allocation -faligned-alloc-unavailable + +// Test that __cpp_aligned_new is not defined when CC1 is passed +// -faligned-alloc-unavailable by the Darwin driver, even when aligned +// allocation is actually enabled. + +// expected-no-diagnostics +#ifdef EXPECT_DEFINED +# ifndef __cpp_aligned_new +# error "__cpp_aligned_new" should be defined +# endif +#else +# ifdef __cpp_aligned_new +# error "__cpp_aligned_new" should not be defined +# endif +#endif diff --git a/test/Lexer/cross-windows-on-linux.cpp b/test/Lexer/cross-windows-on-linux.cpp index 810e1d6ea966f..c6dcbca540561 100644 --- a/test/Lexer/cross-windows-on-linux.cpp +++ b/test/Lexer/cross-windows-on-linux.cpp @@ -8,7 +8,7 @@ // expected to fail on windows as the inclusion would succeed and the // compilation will fail due to the '#error success'. -// XFAIL: win32 +// XFAIL: windows-msvc // This test may or may not fail since 'Inputs\success.h' is passed // to Win32 APIs on Windows. diff --git a/test/Lexer/cxx-features.cpp b/test/Lexer/cxx-features.cpp index 772fa26e96fc1..09b82b7c47ef4 100644 --- a/test/Lexer/cxx-features.cpp +++ b/test/Lexer/cxx-features.cpp @@ -9,53 +9,68 @@ // RUN: %clang_cc1 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation // RUN: %clang_cc1 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s // RUN: %clang_cc1 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s +// RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify -fsized-deallocation %s // expected-no-diagnostics // FIXME using `defined` in a macro has undefined behavior. #if __cplusplus < 201103L -#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98 +#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98) #elif __cplusplus < 201402L -#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11 -#elif __cplusplus < 201406L -#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14 +#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11) +#elif __cplusplus < 201703L +#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14) +#elif __cplusplus <= 201703L +#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17) #else -#define check(macro, cxx98, cxx11, cxx14, cxx17) cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17 +#define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20) +#endif + +// --- C++20 features --- + +#if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811) : \ + defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0) : \ + check(char8_t, 0, 0, 0, 0, 201811) +#error "wrong value for __cpp_char8_t" +#endif + +#if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806) +#error "wrong value for __cpp_impl_destroying_delete" #endif // --- C++17 features --- -#if check(hex_float, 0, 0, 0, 201603) +#if check(hex_float, 0, 0, 0, 201603, 201603) #error "wrong value for __cpp_hex_float" #endif -#if check(inline_variables, 0, 0, 0, 201606) +#if check(inline_variables, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_inline_variables" #endif -#if check(aligned_new, 0, 0, 0, 201606) +#if check(aligned_new, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_aligned_new" #endif -#if check(guaranteed_copy_elision, 0, 0, 0, 201606) +#if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_guaranteed_copy_elision" #endif -#if check(noexcept_function_type, 0, 0, 0, 201510) +#if check(noexcept_function_type, 0, 0, 0, 201510, 201510) #error "wrong value for __cpp_noexcept_function_type" #endif -#if check(fold_expressions, 0, 0, 0, 201603) +#if check(fold_expressions, 0, 0, 0, 201603, 201603) #error "wrong value for __cpp_fold_expressions" #endif -#if check(capture_star_this, 0, 0, 0, 201603) +#if check(capture_star_this, 0, 0, 0, 201603, 201603) #error "wrong value for __cpp_capture_star_this" #endif // constexpr checked below -#if check(if_constexpr, 0, 0, 0, 201606) +#if check(if_constexpr, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_if_constexpr" #endif @@ -63,204 +78,199 @@ // static_assert checked below -#if check(deduction_guides, 0, 0, 0, 201703) +#if check(deduction_guides, 0, 0, 0, 201703, 201703) #error "wrong value for __cpp_deduction_guides" #endif -#if check(nontype_template_parameter_auto, 0, 0, 0, 201606) +#if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_nontype_template_parameter_auto" #endif // This is the old name (from P0096R4) for // __cpp_nontype_template_parameter_auto -#if check(template_auto, 0, 0, 0, 201606) +#if check(template_auto, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_template_auto" #endif -#if check(namespace_attributes, 0, 0, 0, 201411) +#if check(namespace_attributes, 0, 0, 0, 201411, 201411) // FIXME: allowed without warning in C++14 and C++11 #error "wrong value for __cpp_namespace_attributes" #endif -#if check(enumerator_attributes, 0, 0, 0, 201411) +#if check(enumerator_attributes, 0, 0, 0, 201411, 201411) // FIXME: allowed without warning in C++14 and C++11 #error "wrong value for __cpp_enumerator_attributes" #endif // This is an old name (from P0096R4), now removed from SD-6. -#if check(nested_namespace_definitions, 0, 0, 0, 201411) +#if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411) #error "wrong value for __cpp_nested_namespace_definitions" #endif // inheriting_constructors checked below -#if check(variadic_using, 0, 0, 0, 201611) +#if check(variadic_using, 0, 0, 0, 201611, 201611) #error "wrong value for __cpp_variadic_using" #endif -#if check(aggregate_bases, 0, 0, 0, 201603) +#if check(aggregate_bases, 0, 0, 0, 201603, 201603) #error "wrong value for __cpp_aggregate_bases" #endif -#if check(structured_bindings, 0, 0, 0, 201606) +#if check(structured_bindings, 0, 0, 0, 201606, 201606) #error "wrong value for __cpp_structured_bindings" #endif -#if check(nontype_template_args, 0, 0, 0, 201411) +#if check(nontype_template_args, 0, 0, 0, 201411, 201411) #error "wrong value for __cpp_nontype_template_args" #endif #if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \ - ? check(template_template_args, 0, 0, 0, 201611) \ - : check(template_template_args, 0, 0, 0, 0) + ? check(template_template_args, 0, 0, 0, 201611, 201611) \ + : check(template_template_args, 0, 0, 0, 0, 0) #error "wrong value for __cpp_template_template_args" #endif // --- C++14 features --- -#if check(binary_literals, 0, 0, 201304, 201304) +#if check(binary_literals, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_binary_literals" #endif // (Removed from SD-6.) -#if check(digit_separators, 0, 0, 201309, 201309) +#if check(digit_separators, 0, 0, 201309, 201309, 201309) #error "wrong value for __cpp_digit_separators" #endif -#if check(init_captures, 0, 0, 201304, 201304) +#if check(init_captures, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_init_captures" #endif -#if check(generic_lambdas, 0, 0, 201304, 201304) +#if check(generic_lambdas, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_generic_lambdas" #endif -#if check(sized_deallocation, 0, 0, 201309, 201309) +#if check(sized_deallocation, 0, 0, 201309, 201309, 201309) #error "wrong value for __cpp_sized_deallocation" #endif // constexpr checked below -#if check(decltype_auto, 0, 0, 201304, 201304) +#if check(decltype_auto, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_decltype_auto" #endif -#if check(return_type_deduction, 0, 0, 201304, 201304) +#if check(return_type_deduction, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_return_type_deduction" #endif -#if check(runtime_arrays, 0, 0, 0, 0) +#if check(runtime_arrays, 0, 0, 0, 0, 0) #error "wrong value for __cpp_runtime_arrays" #endif -#if check(aggregate_nsdmi, 0, 0, 201304, 201304) +#if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_aggregate_nsdmi" #endif -#if check(variable_templates, 0, 0, 201304, 201304) +#if check(variable_templates, 0, 0, 201304, 201304, 201304) #error "wrong value for __cpp_variable_templates" #endif // --- C++11 features --- -#if check(unicode_characters, 0, 200704, 200704, 200704) +#if check(unicode_characters, 0, 200704, 200704, 200704, 200704) #error "wrong value for __cpp_unicode_characters" #endif -#if check(raw_strings, 0, 200710, 200710, 200710) +#if check(raw_strings, 0, 200710, 200710, 200710, 200710) #error "wrong value for __cpp_raw_strings" #endif -#if check(unicode_literals, 0, 200710, 200710, 200710) +#if check(unicode_literals, 0, 200710, 200710, 200710, 200710) #error "wrong value for __cpp_unicode_literals" #endif -#if check(user_defined_literals, 0, 200809, 200809, 200809) +#if check(user_defined_literals, 0, 200809, 200809, 200809, 200809) #error "wrong value for __cpp_user_defined_literals" #endif -#if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0) : check(threadsafe_static_init, 200806, 200806, 200806, 200806) +#if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0) : \ + check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806) #error "wrong value for __cpp_threadsafe_static_init" #endif -#if check(lambdas, 0, 200907, 200907, 200907) +#if check(lambdas, 0, 200907, 200907, 200907, 200907) #error "wrong value for __cpp_lambdas" #endif -#if check(constexpr, 0, 200704, 201304, 201603) +#if check(constexpr, 0, 200704, 201304, 201603, 201603) #error "wrong value for __cpp_constexpr" #endif -#if check(range_based_for, 0, 200907, 200907, 201603) +#if check(range_based_for, 0, 200907, 200907, 201603, 201603) #error "wrong value for __cpp_range_based_for" #endif -#if check(static_assert, 0, 200410, 200410, 201411) +#if check(static_assert, 0, 200410, 200410, 201411, 201411) #error "wrong value for __cpp_static_assert" #endif -#if check(decltype, 0, 200707, 200707, 200707) +#if check(decltype, 0, 200707, 200707, 200707, 200707) #error "wrong value for __cpp_decltype" #endif -#if check(attributes, 0, 200809, 200809, 200809) +#if check(attributes, 0, 200809, 200809, 200809, 200809) #error "wrong value for __cpp_attributes" #endif -#if check(rvalue_references, 0, 200610, 200610, 200610) +#if check(rvalue_references, 0, 200610, 200610, 200610, 200610) #error "wrong value for __cpp_rvalue_references" #endif -#if check(variadic_templates, 0, 200704, 200704, 200704) +#if check(variadic_templates, 0, 200704, 200704, 200704, 200704) #error "wrong value for __cpp_variadic_templates" #endif -#if check(initializer_lists, 0, 200806, 200806, 200806) +#if check(initializer_lists, 0, 200806, 200806, 200806, 200806) #error "wrong value for __cpp_initializer_lists" #endif -#if check(delegating_constructors, 0, 200604, 200604, 200604) +#if check(delegating_constructors, 0, 200604, 200604, 200604, 200604) #error "wrong value for __cpp_delegating_constructors" #endif -#if check(nsdmi, 0, 200809, 200809, 200809) +#if check(nsdmi, 0, 200809, 200809, 200809, 200809) #error "wrong value for __cpp_nsdmi" #endif -#if check(inheriting_constructors, 0, 201511, 201511, 201511) +#if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511) #error "wrong value for __cpp_inheriting_constructors" #endif -#if check(ref_qualifiers, 0, 200710, 200710, 200710) +#if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710) #error "wrong value for __cpp_ref_qualifiers" #endif -#if check(alias_templates, 0, 200704, 200704, 200704) +#if check(alias_templates, 0, 200704, 200704, 200704, 200704) #error "wrong value for __cpp_alias_templates" #endif // --- C++98 features --- -#if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711) +#if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711, 199711) #error "wrong value for __cpp_rtti" #endif -#if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711) +#if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711, 199711) #error "wrong value for __cpp_exceptions" #endif // --- TS features -- -#if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS) +#if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS, CONCEPTS_TS) #error "wrong value for __cpp_experimental_concepts" #endif -#if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0) +#if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0, 0) #error "wrong value for __cpp_coroutines" #endif - -// --- not-yet-standard features -- - -#if defined(CHAR8_T) ? check(char8_t, 201803, 201803, 201803, 201803) : check(char8_t, 0, 0, 0, 0) -#error "wrong value for __cpp_char8_t" -#endif diff --git a/test/Lexer/has_feature_memory_sanitizer.cpp b/test/Lexer/has_feature_memory_sanitizer.cpp index 3ebb9e13682ac..ca9a39cccdaeb 100644 --- a/test/Lexer/has_feature_memory_sanitizer.cpp +++ b/test/Lexer/has_feature_memory_sanitizer.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -E -fsanitize=memory %s -o - | FileCheck --check-prefix=CHECK-MSAN %s +// RUN: %clang_cc1 -E -fsanitize=kernel-memory %s -o - | FileCheck --check-prefix=CHECK-MSAN %s // RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-MSAN %s #if __has_feature(memory_sanitizer) diff --git a/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp b/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp new file mode 100644 index 0000000000000..62e5316dde58e --- /dev/null +++ b/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp @@ -0,0 +1,13 @@ +// RUN: %clang -E -fsanitize=undefined %s -o - | FileCheck --check-prefix=CHECK-UBSAN %s +// RUN: %clang -E -fsanitize=alignment %s -o - | FileCheck --check-prefix=CHECK-ALIGNMENT %s +// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-NO-UBSAN %s + +#if __has_feature(undefined_behavior_sanitizer) +int UBSanEnabled(); +#else +int UBSanDisabled(); +#endif + +// CHECK-UBSAN: UBSanEnabled +// CHECK-ALIGNMENT: UBSanEnabled +// CHECK-NO-UBSAN: UBSanDisabled diff --git a/test/Lexer/has_feature_xray_instrument.cpp b/test/Lexer/has_feature_xray_instrument.cpp new file mode 100644 index 0000000000000..cd2750d77f9b8 --- /dev/null +++ b/test/Lexer/has_feature_xray_instrument.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -E -fxray-instrument %s -o - | FileCheck --check-prefix=CHECK-XRAY %s +// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NO-XRAY %s + +#if __has_feature(xray_instrument) +int XRayInstrumentEnabled(); +#else +int XRayInstrumentDisabled(); +#endif + +// CHECK-XRAY: XRayInstrumentEnabled +// CHECK-NO-XRAY: XRayInstrumentDisabled diff --git a/test/Lexer/unicode.c b/test/Lexer/unicode.c index 30e353fa797e0..01285fbc21380 100644 --- a/test/Lexer/unicode.c +++ b/test/Lexer/unicode.c @@ -38,3 +38,15 @@ int n; = 3; // expected-warning {{treating Unicode character <U+037E> as identi int *n꞉꞉v = &n;; // expected-warning 2{{treating Unicode character <U+A789> as identifier character rather than as ':' symbol}} // expected-warning@-1 {{treating Unicode character <U+037E> as identifier character rather than as ';' symbol}} int v=[=](auto){return~x;}(); // expected-warning 12{{treating Unicode character}} + +int xx; +// expected-warning@-1 {{identifier contains Unicode character <U+2060> that is invisible in some environments}} +// expected-warning@-2 {{identifier contains Unicode character <U+FEFF> that is invisible in some environments}} +// expected-warning@-3 {{identifier contains Unicode character <U+200D> that is invisible in some environments}} +int foobar = 0; // expected-warning {{identifier contains Unicode character <U+200B> that is invisible in some environments}} +int x = foobar; // expected-error {{undeclared identifier}} + +int ∣foo; // expected-error {{non-ASCII character}} +#ifndef PP_ONLY +#define ∶ x // expected-error {{macro name must be an identifier}} +#endif |
