132 lines · c
1// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -DGNU2// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DGNU -std=c++983// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s -std=c11 -DC11 -D__thread=_Thread_local4// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++985// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11 -D__thread=thread_local -std=c++11 -Wno-deprecated6// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated7// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify=expected,thread-local -pedantic %s -std=c99 -D__thread=_Thread_local -DC998 9__thread int t1; // thread-local-warning {{'_Thread_local' is a C11 extension}}10__thread extern int t2; // thread-local-warning {{'_Thread_local' is a C11 extension}}11__thread static int t3; // thread-local-warning {{'_Thread_local' is a C11 extension}}12#ifdef GNU13// expected-warning@-3 {{'__thread' before 'extern'}}14// expected-warning@-3 {{'__thread' before 'static'}}15#endif16 17__private_extern__ __thread int t4; // thread-local-warning {{'_Thread_local' is a C11 extension}}18struct t5 { __thread int x; }; // thread-local-warning {{'_Thread_local' is a C11 extension}}19#ifdef __cplusplus20// expected-error-re@-2 {{'{{__thread|_Thread_local|thread_local}}' is only allowed on variable declarations}}21#else22// FIXME: The 'is only allowed on variable declarations' diagnostic is better here.23// expected-error@-5 {{type name does not allow storage class to be specified}}24#endif25 26__thread int t6(void); // thread-local-warning {{'_Thread_local' is a C11 extension}}27#if defined(GNU)28// expected-error@-2 {{'__thread' is only allowed on variable declarations}}29#elif defined(C11) || defined(C99)30// expected-error@-4 {{'_Thread_local' is only allowed on variable declarations}}31#else32// expected-error@-6 {{'thread_local' is only allowed on variable declarations}}33#endif34 35int f(__thread int t7) { // expected-error {{' is only allowed on variable declarations}} \36 // thread-local-warning {{'_Thread_local' is a C11 extension}}37 __thread int t8; // thread-local-warning {{'_Thread_local' is a C11 extension}}38#if defined(GNU)39 // expected-error@-2 {{'__thread' variables must have global storage}}40#elif defined(C11) || defined(C99)41 // expected-error@-4 {{'_Thread_local' variables must have global storage}}42#endif43 extern __thread int t9; // thread-local-warning {{'_Thread_local' is a C11 extension}}44 static __thread int t10; // thread-local-warning {{'_Thread_local' is a C11 extension}}45 __private_extern__ __thread int t11; // thread-local-warning {{'_Thread_local' is a C11 extension}}46#if __cplusplus < 201103L47 __thread auto int t12a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local}}' declaration specifier}} \48 // thread-local-warning {{'_Thread_local' is a C11 extension}}49 auto __thread int t12b; // expected-error {{cannot combine with previous 'auto' declaration specifier}} \50 // thread-local-warning {{'_Thread_local' is a C11 extension}}51#elif !defined(CXX11)52 __thread auto t12a = 0; // expected-error {{'_Thread_local' variables must have global storage}} \53 // thread-local-warning {{'_Thread_local' is a C11 extension}}54 auto __thread t12b = 0; // expected-error {{'_Thread_local' variables must have global storage}} \55 // thread-local-warning {{'_Thread_local' is a C11 extension}}56#endif57 __thread register int t13a; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \58 // thread-local-warning {{'_Thread_local' is a C11 extension}}59 register __thread int t13b; // expected-error {{cannot combine with previous 'register' declaration specifier}} \60 // thread-local-warning {{'_Thread_local' is a C11 extension}}61}62 63__thread typedef int t14; // expected-error-re {{cannot combine with previous '{{__thread|_Thread_local|thread_local}}' declaration specifier}} \64 // thread-local-warning {{'_Thread_local' is a C11 extension}}65__thread int t15; // expected-note {{previous definition is here}} \66 // thread-local-warning {{'_Thread_local' is a C11 extension}}67extern int t15; // expected-error {{non-thread-local declaration of 't15' follows thread-local declaration}}68extern int t16; // expected-note {{previous declaration is here}}69__thread int t16; // expected-error {{thread-local declaration of 't16' follows non-thread-local declaration}} \70 // thread-local-warning {{'_Thread_local' is a C11 extension}}71 72#ifdef CXX1173extern thread_local int t17; // expected-note {{previous declaration is here}}74_Thread_local int t17; // expected-error {{thread-local declaration of 't17' with static initialization follows declaration with dynamic initialization}} \75 // expected-warning {{'_Thread_local' is a C11 extension}}76extern _Thread_local int t18; // expected-note {{previous declaration is here}} \77 // expected-warning {{'_Thread_local' is a C11 extension}}78thread_local int t18; // expected-error {{thread-local declaration of 't18' with dynamic initialization follows declaration with static initialization}}79#endif80 81// PR1372082__thread int thread_int; // thread-local-warning {{'_Thread_local' is a C11 extension}}83int *thread_int_ptr = &thread_int;84#ifndef __cplusplus85// expected-error@-2 {{initializer element is not a compile-time constant}}86#endif87void g(void) {88 int *p = &thread_int; // This is perfectly fine, though.89}90#if __cplusplus >= 201103L91constexpr int *thread_int_ptr_2 = &thread_int; // expected-error {{must be initialized by a constant expression}}92#endif93 94int non_const(void);95__thread int non_const_init = non_const(); // thread-local-warning {{'_Thread_local' is a C11 extension}}96#if !defined(__cplusplus)97// expected-error@-2 {{initializer element is not a compile-time constant}}98#elif !defined(CXX11)99// expected-error@-4 {{initializer for thread-local variable must be a constant expression}}100#if __cplusplus >= 201103L101// expected-note@-6 {{use 'thread_local' to allow this}}102#endif103#endif104 105#ifdef __cplusplus106struct S {107 ~S();108};109__thread S s; // thread-local-warning {{'_Thread_local' is a C11 extension}}110#if !defined(CXX11)111// expected-error@-2 {{type of thread-local variable has non-trivial destruction}}112#if __cplusplus >= 201103L113// expected-note@-4 {{use 'thread_local' to allow this}}114#endif115#endif116#endif117 118#ifdef __cplusplus119struct HasCtor {120 HasCtor();121};122__thread HasCtor var_with_ctor; // thread-local-warning {{'_Thread_local' is a C11 extension}}123#if !defined(CXX11)124// expected-error@-2 {{initializer for thread-local variable must be a constant expression}}125#if __cplusplus >= 201103L126// expected-note@-4 {{use 'thread_local' to allow this}}127#endif128#endif129#endif130 131__thread int aggregate[10] = {0}; // thread-local-warning {{'_Thread_local' is a C11 extension}}132