diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-12-01 01:07:10 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-12-01 01:07:10 +0000 |
commit | edbf5972a4c912d9e03b6c33ef73872603ca0522 (patch) | |
tree | f01204d787c20d46e5cf8ed2c11ea80ba031375c /clang/test/Lexer | |
parent | 3e89b083037e5cff896d15e52de7a32d9e80ff5a (diff) | |
download | bcm5719-llvm-edbf5972a4c912d9e03b6c33ef73872603ca0522.tar.gz bcm5719-llvm-edbf5972a4c912d9e03b6c33ef73872603ca0522.zip |
[c++2a] P0515R3: lexer support for new <=> token.
llvm-svn: 319509
Diffstat (limited to 'clang/test/Lexer')
-rw-r--r-- | clang/test/Lexer/cxx2a-spaceship.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp b/clang/test/Lexer/cxx2a-spaceship.cpp new file mode 100644 index 00000000000..f407937c4e3 --- /dev/null +++ b/clang/test/Lexer/cxx2a-spaceship.cpp @@ -0,0 +1,73 @@ +// RUN: %clang_cc1 -std=c++17 %s -verify +// RUN: %clang_cc1 -std=c++2a %s -verify +// RUN: %clang_cc1 -std=c++2a %s -verify -Wc++17-compat -DCOMPAT +// +// RUN: %clang_cc1 -std=c++17 %s -E -o - | FileCheck %s --check-prefix=CXX17 +// RUN: %clang_cc1 -std=c++2a %s -E -o - | FileCheck %s --check-prefix=CXX20 + +namespace N { + +struct A {}; +void operator<=(A, A); +#if __cplusplus > 201703L +void operator<=>(A, A); // expected-error {{}} +#ifdef COMPAT +// expected-warning@-2 {{'<=>' operator is incompatible with C++ standards before C++2a}} +#endif +#endif + +template<auto> struct X {}; +X<operator<=> +#if __cplusplus <= 201703L + // expected-warning@-2 {{'<=>' is a single token in C++2a; add a space to avoid a change in behavior}} +#else + > // expected-error@-4 {{}} +#endif +#ifdef COMPAT +// expected-warning@-7 {{'<=>' operator is incompatible with C++ standards before C++2a}} +#endif + x; +} + +// <=> can be formed by pasting other comparison operators. +#if __cplusplus > 201703L +#define STR(x) #x +#define STR_EXPANDED(x) STR(x) +#define PASTE(x, y) x ## y +constexpr char a[] = STR_EXPANDED(PASTE(<, =>)); +constexpr char b[] = STR_EXPANDED(PASTE(<=, >)); +static_assert(__builtin_strcmp(a, "<=>") == 0); +static_assert(__builtin_strcmp(b, "<=>") == 0); +#endif + +// -E must not accidentally form a <=> token. + +// CXX17: preprocess1: < => +// CXX17: preprocess2: <=> +// CXX17: preprocess3: < => +// CXX17: preprocess4: <=>= +// CXX17: preprocess5: <=>> +// CXX17: preprocess6: <=>>= +// CXX17: preprocess7: <=> +// CXX17: preprocess8: <=>= +// +// CXX20: preprocess1: < => +// CXX20: preprocess2: <= > +// CXX20: preprocess3: < => +// CXX20: preprocess4: <= >= +// CXX20: preprocess5: <= >> +// CXX20: preprocess6: <= >>= +// CXX20: preprocess7: <=> +// CXX20: preprocess8: <=>= + +#define ID(x) x +[[some_vendor::some_attribute( // expected-warning {{unknown attribute}} +preprocess1: ID(<)ID(=>), +preprocess2: ID(<=)ID(>), +preprocess3: ID(<)ID(=)ID(>), +preprocess4: ID(<=)ID(>=), +preprocess5: ID(<=)ID(>>), +preprocess6: ID(<=)ID(>>=), +preprocess7: ID(<=>) // expected-warning 0-1{{'<=>'}} +preprocess8: ID(<=>=) // expected-warning 0-1{{'<=>'}} +)]]; |