diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2019-08-27 19:15:24 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2019-08-27 19:15:24 +0000 |
commit | 5f0d7648a30ecf9d250486ba0ea07d02f1accef3 (patch) | |
tree | 5ad3787dcc4c348c063630cc8a260e8fbaaafad1 | |
parent | fff88111a219083406a561e1ff22f0280f021d6b (diff) | |
download | clang-5f0d7648a30ecf9d250486ba0ea07d02f1accef3.tar.gz |
Diagnose both _Complex and _Imaginary as C99 extensions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370100 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
-rw-r--r-- | lib/Parse/ParseDecl.cpp | 4 | ||||
-rw-r--r-- | test/Parser/c99.c | 8 | ||||
-rw-r--r-- | test/SemaCXX/compare-cxx2a.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/complex-init-list.cpp | 4 | ||||
-rw-r--r-- | test/SemaCXX/constant-expression-cxx11.cpp | 18 |
6 files changed, 28 insertions, 16 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index edeab1e98a..c0b0f444df 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -124,6 +124,8 @@ def err_duplicate_default_assoc : Error< def note_previous_default_assoc : Note< "previous default generic association is here">; +def ext_c99_feature : Extension< + "'%0' is a C99 extension">, InGroup<C99>; def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup<C11>; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 9b3b5c77ff..6c3b6d6e62 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -3689,10 +3689,14 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, DiagID); break; case tok::kw__Complex: + if (!getLangOpts().C99) + Diag(Tok, diag::ext_c99_feature) << Tok.getName(); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec, DiagID); break; case tok::kw__Imaginary: + if (!getLangOpts().C99) + Diag(Tok, diag::ext_c99_feature) << Tok.getName(); isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec, DiagID); break; diff --git a/test/Parser/c99.c b/test/Parser/c99.c new file mode 100644 index 0000000000..3828f2057a --- /dev/null +++ b/test/Parser/c99.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -std=c99 %s +// RUN: %clang_cc1 -verify=expected,ext -pedantic -Wno-comment -fsyntax-only -std=c89 %s +// RUN: %clang_cc1 -verify=expected,ext -pedantic -fsyntax-only -x c++ %s + +double _Imaginary foo; // ext-warning {{'_Imaginary' is a C99 extension}} \ + // expected-error {{imaginary types are not supported}} +double _Complex bar; // ext-warning {{'_Complex' is a C99 extension}} + diff --git a/test/SemaCXX/compare-cxx2a.cpp b/test/SemaCXX/compare-cxx2a.cpp index 89597587d5..c68a0ae913 100644 --- a/test/SemaCXX/compare-cxx2a.cpp +++ b/test/SemaCXX/compare-cxx2a.cpp @@ -398,8 +398,8 @@ enum class StrongE {}; enum WeakE { E_One, E_Two }; -void test_diag(_Complex int ci, _Complex float cf, _Complex double cd, int i, float f, StrongE E1, WeakE E2, int *p) { - (void)(ci <=> (_Complex int &)ci); +void test_diag(_Complex int ci, _Complex float cf, _Complex double cd, int i, float f, StrongE E1, WeakE E2, int *p) { // expected-warning 3 {{'_Complex' is a C99 extension}} + (void)(ci <=> (_Complex int &)ci); // expected-warning {{'_Complex' is a C99 extension}} (void)(ci <=> cf); (void)(ci <=> i); (void)(ci <=> f); @@ -410,12 +410,12 @@ void test_diag(_Complex int ci, _Complex float cf, _Complex double cd, int i, fl (void)(E2 <=> cf); // expected-error {{invalid operands}} } -void test_int(_Complex int x, _Complex int y) { +void test_int(_Complex int x, _Complex int y) { // expected-warning 2 {{'_Complex' is a C99 extension}} auto r = x <=> y; ASSERT_EXPR_TYPE(r, std::strong_equality); } -void test_double(_Complex double x, _Complex double y) { +void test_double(_Complex double x, _Complex double y) { // expected-warning 2 {{'_Complex' is a C99 extension}} auto r = x <=> y; ASSERT_EXPR_TYPE(r, std::weak_equality); } diff --git a/test/SemaCXX/complex-init-list.cpp b/test/SemaCXX/complex-init-list.cpp index f70f9df6c7..ea7b688ab2 100644 --- a/test/SemaCXX/complex-init-list.cpp +++ b/test/SemaCXX/complex-init-list.cpp @@ -1,5 +1,4 @@ // 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, @@ -11,5 +10,4 @@ // test/Sema/complex-init-list.c. // Basic testcase -// (No pedantic warning is necessary because _Complex is not part of C++.) -_Complex float valid1 = { 1.0f, 2.0f }; +_Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{'_Complex' is a C99 extension}} diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 2f3fe09bfb..e9e083950c 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -1287,13 +1287,13 @@ namespace ExternConstexpr { } namespace ComplexConstexpr { - constexpr _Complex float test1 = {}; - constexpr _Complex float test2 = {1}; - constexpr _Complex double test3 = {1,2}; - constexpr _Complex int test4 = {4}; - constexpr _Complex int test5 = 4; - constexpr _Complex int test6 = {5,6}; - typedef _Complex float fcomplex; + constexpr _Complex float test1 = {}; // expected-warning {{'_Complex' is a C99 extension}} + constexpr _Complex float test2 = {1}; // expected-warning {{'_Complex' is a C99 extension}} + constexpr _Complex double test3 = {1,2}; // expected-warning {{'_Complex' is a C99 extension}} + constexpr _Complex int test4 = {4}; // expected-warning {{'_Complex' is a C99 extension}} + constexpr _Complex int test5 = 4; // expected-warning {{'_Complex' is a C99 extension}} + constexpr _Complex int test6 = {5,6}; // expected-warning {{'_Complex' is a C99 extension}} + typedef _Complex float fcomplex; // expected-warning {{'_Complex' is a C99 extension}} constexpr fcomplex test7 = fcomplex(); constexpr const double &t2r = __real test3; @@ -1307,10 +1307,10 @@ namespace ComplexConstexpr { static_assert(t2p[1] == 2.0, ""); static_assert(t2p[2] == 0.0, ""); // expected-error {{constant expr}} expected-note {{one-past-the-end pointer}} static_assert(t2p[3] == 0.0, ""); // expected-error {{constant expr}} expected-note {{cannot refer to element 3 of array of 2 elements}} - constexpr _Complex float *p = 0; + constexpr _Complex float *p = 0; // expected-warning {{'_Complex' is a C99 extension}} constexpr float pr = __real *p; // expected-error {{constant expr}} expected-note {{cannot access real component of null}} constexpr float pi = __imag *p; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of null}} - constexpr const _Complex double *q = &test3 + 1; + constexpr const _Complex double *q = &test3 + 1; // expected-warning {{'_Complex' is a C99 extension}} constexpr double qr = __real *q; // expected-error {{constant expr}} expected-note {{cannot access real component of pointer past the end}} constexpr double qi = __imag *q; // expected-error {{constant expr}} expected-note {{cannot access imaginary component of pointer past the end}} |