TestNoAutoType.cpp (2421B)
1 #define MOZ_NON_AUTOABLE __attribute__((annotate("moz_non_autoable"))) 2 #define MOZ_RUNINIT __attribute__((annotate("moz_global_var"))) 3 4 template<class T> 5 struct MOZ_NON_AUTOABLE ExplicitTypeTemplate {}; 6 struct MOZ_NON_AUTOABLE ExplicitType {}; 7 struct NonExplicitType {}; 8 9 void f() { 10 { 11 ExplicitType a; 12 auto b = a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitType'}} expected-note {{Please write out this type explicitly}} 13 auto &br = a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitType &'}} expected-note {{Please write out this type explicitly}} 14 const auto &brc = a; // expected-error {{Cannot use auto to declare a variable of type 'const ExplicitType &'}} expected-note {{Please write out this type explicitly}} 15 auto *bp = &a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitType *'}} expected-note {{Please write out this type explicitly}} 16 const auto *bpc = &a; // expected-error {{Cannot use auto to declare a variable of type 'const ExplicitType *'}} expected-note {{Please write out this type explicitly}} 17 } 18 19 { 20 ExplicitTypeTemplate<int> a; 21 auto b = a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitTypeTemplate<int>'}} expected-note {{Please write out this type explicitly}} 22 auto &br = a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitTypeTemplate<int> &'}} expected-note {{Please write out this type explicitly}} 23 const auto &brc = a; // expected-error {{Cannot use auto to declare a variable of type 'const ExplicitTypeTemplate<int> &'}} expected-note {{Please write out this type explicitly}} 24 auto *bp = &a; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitTypeTemplate<int> *'}} expected-note {{Please write out this type explicitly}} 25 const auto *bpc = &a; // expected-error {{Cannot use auto to declare a variable of type 'const ExplicitTypeTemplate<int> *'}} expected-note {{Please write out this type explicitly}} 26 } 27 28 { 29 NonExplicitType c; 30 auto d = c; 31 auto &dr = c; 32 const auto &drc = c; 33 auto *dp = &c; 34 const auto *dpc = &c; 35 } 36 } 37 38 ExplicitType A; 39 MOZ_RUNINIT auto B = A; // expected-error {{Cannot use auto to declare a variable of type 'ExplicitType'}} expected-note {{Please write out this type explicitly}} 40 41 NonExplicitType C; 42 MOZ_RUNINIT auto D = C;