blob: 947bb3c5f406dcb44688004ac8a9372879b0faa6 [file] [log] [blame]
Richard Smith4cf4a5e2013-03-28 01:55:44 +00001// RUN: %clang_cc1 -verify -pedantic %s
Richard Smith83271182012-02-11 18:03:45 +00002
3template<typename T> struct atomic {
4 _Atomic(T) value;
Richard Smith4cf4a5e2013-03-28 01:55:44 +00005
6 void f() _Atomic; // expected-error {{expected ';' at end of declaration list}}
Richard Smith83271182012-02-11 18:03:45 +00007};
8
9template<typename T> struct user {
10 struct inner { char n[sizeof(T)]; };
11 atomic<inner> i;
12};
13
14user<int> u;
Douglas Gregorf7ecc302012-04-12 17:51:55 +000015
16// Test overloading behavior of atomics.
17struct A { };
18
19int &ovl1(_Atomic(int));
Richard Smith4cf4a5e2013-03-28 01:55:44 +000020int &ovl1(_Atomic int); // ok, redeclaration
Douglas Gregorf7ecc302012-04-12 17:51:55 +000021long &ovl1(_Atomic(long));
22float &ovl1(_Atomic(float));
23double &ovl1(_Atomic(A const *const *));
Richard Smith4cf4a5e2013-03-28 01:55:44 +000024double &ovl1(A const *const *_Atomic);
Douglas Gregorf7ecc302012-04-12 17:51:55 +000025short &ovl1(_Atomic(A **));
26
27void test_overloading(int i, float f, _Atomic(int) ai, _Atomic(float) af,
28 long l, _Atomic(long) al, A const *const *acc,
29 A const ** ac, A **a) {
30 int& ir1 = ovl1(i);
31 int& ir2 = ovl1(ai);
32 long& lr1 = ovl1(l);
33 long& lr2 = ovl1(al);
34 float &fr1 = ovl1(f);
35 float &fr2 = ovl1(af);
36 double &dr1 = ovl1(acc);
37 double &dr2 = ovl1(ac);
38 short &sr1 = ovl1(a);
39}
Richard Smith4cf4a5e2013-03-28 01:55:44 +000040
41typedef int (A::*fp)() _Atomic; // expected-error {{expected ';' after top level declarator}} expected-warning {{does not declare anything}}
42
43typedef _Atomic(int(A::*)) atomic_mem_ptr_to_int;
44typedef int(A::*_Atomic atomic_mem_ptr_to_int);
45
46typedef _Atomic(int)(A::*mem_ptr_to_atomic_int);
47typedef _Atomic int(A::*mem_ptr_to_atomic_int);
48
49typedef _Atomic(int)&atomic_int_ref;
50typedef _Atomic int &atomic_int_ref;
51typedef _Atomic atomic_int_ref atomic_int_ref; // ok, qualifiers on references ignored in this case.
52
53typedef int &_Atomic atomic_reference_to_int; // expected-error {{'_Atomic' qualifier may not be applied to a reference}}
54typedef _Atomic(int &) atomic_reference_to_int; // expected-error {{_Atomic cannot be applied to reference type 'int &'}}
55
56struct S {
57 _Atomic union { int n; }; // expected-warning {{anonymous union cannot be '_Atomic'}}
58};