Skip to content

Commit 5cd5d56

Browse files
committed
Diagnose _Atomic as a C11 extension.
llvm-svn: 370982
1 parent 48c6fad commit 5cd5d56

File tree

4 files changed

+86
-65
lines changed

4 files changed

+86
-65
lines changed

clang/lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,9 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
39243924
// If the _Atomic keyword is immediately followed by a left parenthesis,
39253925
// it is interpreted as a type specifier (with a type name), not as a
39263926
// type qualifier.
3927+
if (!getLangOpts().C11)
3928+
Diag(Tok, diag::ext_c11_feature) << Tok.getName();
3929+
39273930
if (NextToken().is(tok::l_paren)) {
39283931
ParseAtomicSpecifier(DS);
39293932
continue;
@@ -5330,6 +5333,8 @@ void Parser::ParseTypeQualifierListOpt(
53305333
case tok::kw__Atomic:
53315334
if (!AtomicAllowed)
53325335
goto DoneWithTypeQuals;
5336+
if (!getLangOpts().C11)
5337+
Diag(Tok, diag::ext_c11_feature) << Tok.getName();
53335338
isInvalid = DS.SetTypeQual(DeclSpec::TQ_atomic, Loc, PrevSpec, DiagID,
53345339
getLangOpts());
53355340
break;

clang/test/Parser/atomic.c

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
11
// RUN: %clang_cc1 -std=c11 %s -fsyntax-only -verify -pedantic
2+
// RUN: %clang_cc1 -std=c99 %s -fsyntax-only -verify=expected,ext -pedantic -Wno-typedef-redefinition
23

3-
typedef _Atomic(int) atomic_int;
4-
typedef _Atomic int atomic_int;
5-
typedef _Atomic _Atomic _Atomic(int) atomic_int; // expected-warning {{duplicate '_Atomic' declaration specifier}}
4+
typedef _Atomic(int) atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
5+
typedef _Atomic int atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
6+
typedef _Atomic _Atomic _Atomic(int) atomic_int; // expected-warning {{duplicate '_Atomic' declaration specifier}} \
7+
// ext-warning 3 {{'_Atomic' is a C11 extension}}
68

79
typedef const int const_int;
810

911
typedef const atomic_int const_atomic_int;
10-
typedef _Atomic const int const_atomic_int;
11-
typedef const _Atomic int const_atomic_int;
12-
typedef const _Atomic(int) const_atomic_int;
13-
typedef const _Atomic(_Atomic int) const_atomic_int; // expected-error {{_Atomic cannot be applied to atomic type '_Atomic(int)'}}
14-
typedef _Atomic const_int const_atomic_int;
15-
typedef _Atomic(const_int) const_atomic_int; // expected-error {{_Atomic cannot be applied to qualified type 'const_int' (aka 'const int')}}
16-
17-
typedef int *_Atomic atomic_int_ptr;
18-
typedef _Atomic(int *) atomic_int_ptr;
19-
typedef int (*_Atomic atomic_int_ptr);
20-
21-
typedef int _Atomic *int_atomic_ptr;
22-
typedef _Atomic(int) *int_atomic_ptr;
12+
typedef _Atomic const int const_atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
13+
typedef const _Atomic int const_atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
14+
typedef const _Atomic(int) const_atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
15+
typedef const _Atomic(_Atomic int) const_atomic_int; // expected-error {{_Atomic cannot be applied to atomic type '_Atomic(int)'}} \
16+
// ext-warning 2 {{'_Atomic' is a C11 extension}}
17+
typedef _Atomic const_int const_atomic_int; // ext-warning {{'_Atomic' is a C11 extension}}
18+
typedef _Atomic(const_int) const_atomic_int; // expected-error {{_Atomic cannot be applied to qualified type 'const_int' (aka 'const int')}} \
19+
// ext-warning {{'_Atomic' is a C11 extension}}
20+
21+
typedef int *_Atomic atomic_int_ptr; // ext-warning {{'_Atomic' is a C11 extension}}
22+
typedef _Atomic(int *) atomic_int_ptr; // ext-warning {{'_Atomic' is a C11 extension}}
23+
typedef int (*_Atomic atomic_int_ptr); // ext-warning {{'_Atomic' is a C11 extension}}
24+
25+
typedef int _Atomic *int_atomic_ptr; // ext-warning {{'_Atomic' is a C11 extension}}
26+
typedef _Atomic(int) *int_atomic_ptr; // ext-warning {{'_Atomic' is a C11 extension}}
2327

2428
typedef int int_fn();
25-
typedef _Atomic int_fn atomic_int_fn; // expected-error {{_Atomic cannot be applied to function type 'int_fn' (aka 'int ()')}}
26-
typedef _Atomic int atomic_int_array[3];
27-
typedef _Atomic atomic_int_array atomic_int_atomic_array; // expected-error {{_Atomic cannot be applied to array type 'atomic_int_array' (aka '_Atomic(int) [3]')}}
29+
typedef _Atomic int_fn atomic_int_fn; // expected-error {{_Atomic cannot be applied to function type 'int_fn' (aka 'int ()')}} \
30+
// ext-warning {{'_Atomic' is a C11 extension}}
31+
typedef _Atomic int atomic_int_array[3]; // ext-warning {{'_Atomic' is a C11 extension}}
32+
typedef _Atomic atomic_int_array atomic_int_atomic_array; // expected-error {{_Atomic cannot be applied to array type 'atomic_int_array' (aka '_Atomic(int) [3]')}} \
33+
// ext-warning {{'_Atomic' is a C11 extension}}
2834

29-
_Atomic struct S { int n; }; // expected-warning {{'_Atomic' ignored on this declaration}}
35+
_Atomic struct S { int n; }; // expected-warning {{'_Atomic' ignored on this declaration}} \
36+
// ext-warning {{'_Atomic' is a C11 extension}}
3037

31-
typedef _Atomic int __attribute__((address_space(1))) atomic_addr_space_int;
32-
typedef _Atomic(int) __attribute__((address_space(1))) atomic_addr_space_int;
38+
typedef _Atomic int __attribute__((address_space(1))) atomic_addr_space_int; // ext-warning {{'_Atomic' is a C11 extension}}
39+
typedef _Atomic(int) __attribute__((address_space(1))) atomic_addr_space_int; // ext-warning {{'_Atomic' is a C11 extension}}
3340

34-
typedef _Atomic int __attribute__((vector_size(16))) atomic_vector_int;
35-
typedef _Atomic(int __attribute__((vector_size(16)))) atomic_vector_int;
41+
typedef _Atomic int __attribute__((vector_size(16))) atomic_vector_int; // ext-warning {{'_Atomic' is a C11 extension}}
42+
typedef _Atomic(int __attribute__((vector_size(16)))) atomic_vector_int; // ext-warning {{'_Atomic' is a C11 extension}}
3643

3744
struct S
38-
_Atomic atomic_s_no_missing_semicolon;
45+
_Atomic atomic_s_no_missing_semicolon; // ext-warning {{'_Atomic' is a C11 extension}}
3946

40-
int *const _Atomic atomic_return_type();
47+
int *const _Atomic atomic_return_type(); // ext-warning {{'_Atomic' is a C11 extension}}

clang/test/SemaCXX/atomic-type.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang_cc1 -verify -pedantic %s -std=c++11
33

44
template<typename T> struct atomic {
5-
_Atomic(T) value;
5+
_Atomic(T) value; // expected-warning {{'_Atomic' is a C11 extension}}
66

77
void f() _Atomic; // expected-error {{expected ';' at end of declaration list}}
88
};
@@ -17,16 +17,16 @@ user<int> u;
1717
// Test overloading behavior of atomics.
1818
struct A { };
1919

20-
int &ovl1(_Atomic(int));
21-
int &ovl1(_Atomic int); // ok, redeclaration
22-
long &ovl1(_Atomic(long));
23-
float &ovl1(_Atomic(float));
24-
double &ovl1(_Atomic(A const *const *));
25-
double &ovl1(A const *const *_Atomic);
26-
short &ovl1(_Atomic(A **));
20+
int &ovl1(_Atomic(int)); // expected-warning {{'_Atomic' is a C11 extension}}
21+
int &ovl1(_Atomic int); // expected-warning {{'_Atomic' is a C11 extension}} // ok, redeclaration
22+
long &ovl1(_Atomic(long)); // expected-warning {{'_Atomic' is a C11 extension}}
23+
float &ovl1(_Atomic(float)); // expected-warning {{'_Atomic' is a C11 extension}}
24+
double &ovl1(_Atomic(A const *const *)); // expected-warning {{'_Atomic' is a C11 extension}}
25+
double &ovl1(A const *const *_Atomic); // expected-warning {{'_Atomic' is a C11 extension}}
26+
short &ovl1(_Atomic(A **)); // expected-warning {{'_Atomic' is a C11 extension}}
2727

28-
void test_overloading(int i, float f, _Atomic(int) ai, _Atomic(float) af,
29-
long l, _Atomic(long) al, A const *const *acc,
28+
void test_overloading(int i, float f, _Atomic(int) ai, _Atomic(float) af, // expected-warning 2 {{'_Atomic' is a C11 extension}}
29+
long l, _Atomic(long) al, A const *const *acc, // expected-warning {{'_Atomic' is a C11 extension}}
3030
A const ** ac, A **a) {
3131
int& ir1 = ovl1(i);
3232
int& ir2 = ovl1(ai);
@@ -39,45 +39,53 @@ void test_overloading(int i, float f, _Atomic(int) ai, _Atomic(float) af,
3939
short &sr1 = ovl1(a);
4040
}
4141

42-
typedef int (A::*fp)() _Atomic; // expected-error {{expected ';' after top level declarator}} expected-warning {{does not declare anything}}
42+
typedef int (A::*fp)() _Atomic; // expected-error {{expected ';' after top level declarator}} expected-warning {{does not declare anything}} \
43+
// expected-warning {{'_Atomic' is a C11 extension}}
4344

44-
typedef _Atomic(int(A::*)) atomic_mem_ptr_to_int;
45-
typedef int(A::*_Atomic atomic_mem_ptr_to_int);
45+
typedef _Atomic(int(A::*)) atomic_mem_ptr_to_int; // expected-warning {{'_Atomic' is a C11 extension}}
46+
typedef int(A::*_Atomic atomic_mem_ptr_to_int); // expected-warning {{'_Atomic' is a C11 extension}}
4647

47-
typedef _Atomic(int)(A::*mem_ptr_to_atomic_int);
48-
typedef _Atomic int(A::*mem_ptr_to_atomic_int);
48+
typedef _Atomic(int)(A::*mem_ptr_to_atomic_int); // expected-warning {{'_Atomic' is a C11 extension}}
49+
typedef _Atomic int(A::*mem_ptr_to_atomic_int); // expected-warning {{'_Atomic' is a C11 extension}}
4950

50-
typedef _Atomic(int)&atomic_int_ref;
51-
typedef _Atomic int &atomic_int_ref;
52-
typedef _Atomic atomic_int_ref atomic_int_ref; // expected-warning {{'_Atomic' qualifier on reference type 'atomic_int_ref' (aka '_Atomic(int) &') has no effect}}
51+
typedef _Atomic(int)&atomic_int_ref; // expected-warning {{'_Atomic' is a C11 extension}}
52+
typedef _Atomic int &atomic_int_ref; // expected-warning {{'_Atomic' is a C11 extension}}
53+
typedef _Atomic atomic_int_ref atomic_int_ref; // expected-warning {{'_Atomic' qualifier on reference type 'atomic_int_ref' (aka '_Atomic(int) &') has no effect}} \
54+
// expected-warning {{'_Atomic' is a C11 extension}}
5355

54-
typedef int &_Atomic atomic_reference_to_int; // expected-error {{'_Atomic' qualifier may not be applied to a reference}}
55-
typedef _Atomic(int &) atomic_reference_to_int; // expected-error {{_Atomic cannot be applied to reference type 'int &'}}
56+
typedef int &_Atomic atomic_reference_to_int; // expected-error {{'_Atomic' qualifier may not be applied to a reference}} \
57+
// expected-warning {{'_Atomic' is a C11 extension}}
58+
typedef _Atomic(int &) atomic_reference_to_int; // expected-error {{_Atomic cannot be applied to reference type 'int &'}} \
59+
// expected-warning {{'_Atomic' is a C11 extension}}
5660

5761
struct S {
58-
_Atomic union { int n; }; // expected-warning {{anonymous union cannot be '_Atomic'}}
62+
_Atomic union { int n; }; // expected-warning {{anonymous union cannot be '_Atomic'}} \
63+
// expected-warning {{'_Atomic' is a C11 extension}}
5964
};
6065

6166
namespace copy_init {
6267
struct X {
6368
X(int);
6469
int n;
6570
};
66-
_Atomic(X) y = X(0);
67-
_Atomic(X) z(X(0));
71+
_Atomic(X) y = X(0); // expected-warning {{'_Atomic' is a C11 extension}}
72+
_Atomic(X) z(X(0)); // expected-warning {{'_Atomic' is a C11 extension}}
6873
void f() { y = X(0); }
6974

70-
_Atomic(X) e1(0); // expected-error {{cannot initialize}}
75+
_Atomic(X) e1(0); // expected-error {{cannot initialize}} \
76+
// expected-warning {{'_Atomic' is a C11 extension}}
7177
#if __cplusplus >= 201103L
72-
_Atomic(X) e2{0}; // expected-error {{illegal initializer}}
73-
_Atomic(X) a{X(0)};
78+
_Atomic(X) e2{0}; // expected-error {{illegal initializer}} \
79+
// expected-warning {{'_Atomic' is a C11 extension}}
80+
_Atomic(X) a{X(0)}; // expected-warning {{'_Atomic' is a C11 extension}}
7481
// FIXME: This does not seem like the right answer.
75-
_Atomic(int) e3{0}; // expected-error {{illegal initializer}}
82+
_Atomic(int) e3{0}; // expected-error {{illegal initializer}} \
83+
// expected-warning {{'_Atomic' is a C11 extension}}
7684
#endif
7785

7886
struct Y {
79-
_Atomic(X) a;
80-
_Atomic(int) b;
87+
_Atomic(X) a; // expected-warning {{'_Atomic' is a C11 extension}}
88+
_Atomic(int) b; // expected-warning {{'_Atomic' is a C11 extension}}
8189
};
8290
Y y1 = { X(0), 4 };
8391
Y y2 = { 0, 4 }; // expected-error {{cannot initialize}}
@@ -87,10 +95,11 @@ namespace copy_init {
8795
// same answer in all these cases:
8896
Y y3 = { X(0), { 4 } }; // expected-error {{illegal initializer type}}
8997
Y y4 = { { X(0) }, 4 };
90-
_Atomic(int) ai = { 4 }; // expected-error {{illegal initializer type}}
91-
_Atomic(X) ax = { X(0) };
98+
_Atomic(int) ai = { 4 }; // expected-error {{illegal initializer type}} \
99+
// expected-warning {{'_Atomic' is a C11 extension}}
100+
_Atomic(X) ax = { X(0) }; // expected-warning {{'_Atomic' is a C11 extension}}
92101
}
93102

94-
bool PR21836(_Atomic(int) *x) {
103+
bool PR21836(_Atomic(int) *x) { // expected-warning {{'_Atomic' is a C11 extension}}
95104
return *x;
96105
}

clang/test/SemaCXX/constant-expression-cxx11.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,21 +1322,21 @@ namespace ComplexConstexpr {
13221322
// _Atomic(T) is exactly like T for the purposes of constant expression
13231323
// evaluation..
13241324
namespace Atomic {
1325-
constexpr _Atomic int n = 3;
1325+
constexpr _Atomic int n = 3; // expected-warning {{'_Atomic' is a C11 extension}}
13261326

1327-
struct S { _Atomic(double) d; };
1327+
struct S { _Atomic(double) d; }; // expected-warning {{'_Atomic' is a C11 extension}}
13281328
constexpr S s = { 0.5 };
13291329
constexpr double d1 = s.d;
13301330
constexpr double d2 = n;
1331-
constexpr _Atomic double d3 = n;
1331+
constexpr _Atomic double d3 = n; // expected-warning {{'_Atomic' is a C11 extension}}
13321332

1333-
constexpr _Atomic(int) n2 = d3;
1333+
constexpr _Atomic(int) n2 = d3; // expected-warning {{'_Atomic' is a C11 extension}}
13341334
static_assert(d1 == 0.5, "");
13351335
static_assert(d3 == 3.0, "");
13361336

13371337
namespace PR16056 {
13381338
struct TestVar {
1339-
_Atomic(int) value;
1339+
_Atomic(int) value; // expected-warning {{'_Atomic' is a C11 extension}}
13401340
constexpr TestVar(int value) : value(value) {}
13411341
};
13421342
constexpr TestVar testVar{-1};
@@ -1345,11 +1345,11 @@ namespace Atomic {
13451345

13461346
namespace PR32034 {
13471347
struct A {};
1348-
struct B { _Atomic(A) a; };
1348+
struct B { _Atomic(A) a; }; // expected-warning {{'_Atomic' is a C11 extension}}
13491349
constexpr int n = (B(), B(), 0);
13501350

13511351
struct C { constexpr C() {} void *self = this; };
1352-
constexpr _Atomic(C) c = C();
1352+
constexpr _Atomic(C) c = C(); // expected-warning {{'_Atomic' is a C11 extension}}
13531353
}
13541354
}
13551355

0 commit comments

Comments
 (0)