diff options
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 30 | ||||
| -rw-r--r-- | clang/test/SemaCXX/cxx11-thread-unsupported.cpp | 5 |
2 files changed, 19 insertions, 16 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b63863e96bb..d44f1417762 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5613,22 +5613,20 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, NewVD->setLocalExternDecl(); if (DeclSpec::TSCS TSCS = D.getDeclSpec().getThreadStorageClassSpec()) { - if (NewVD->hasLocalStorage()) { - // C++11 [dcl.stc]p4: - // When thread_local is applied to a variable of block scope the - // storage-class-specifier static is implied if it does not appear - // explicitly. - // Core issue: 'static' is not implied if the variable is declared - // 'extern'. - if (SCSpec == DeclSpec::SCS_unspecified && - TSCS == DeclSpec::TSCS_thread_local && - DC->isFunctionOrMethod()) - NewVD->setTSCSpec(TSCS); - else - Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(), - diag::err_thread_non_global) - << DeclSpec::getSpecifierName(TSCS); - } else if (!Context.getTargetInfo().isTLSSupported()) + // C++11 [dcl.stc]p4: + // When thread_local is applied to a variable of block scope the + // storage-class-specifier static is implied if it does not appear + // explicitly. + // Core issue: 'static' is not implied if the variable is declared + // 'extern'. + if (NewVD->hasLocalStorage() && + (SCSpec != DeclSpec::SCS_unspecified || + TSCS != DeclSpec::TSCS_thread_local || + !DC->isFunctionOrMethod())) + Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(), + diag::err_thread_non_global) + << DeclSpec::getSpecifierName(TSCS); + else if (!Context.getTargetInfo().isTLSSupported()) Diag(D.getDeclSpec().getThreadStorageClassSpecLoc(), diag::err_thread_unsupported); else diff --git a/clang/test/SemaCXX/cxx11-thread-unsupported.cpp b/clang/test/SemaCXX/cxx11-thread-unsupported.cpp new file mode 100644 index 00000000000..d3fcf82ef41 --- /dev/null +++ b/clang/test/SemaCXX/cxx11-thread-unsupported.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -std=c++11 -triple=x86_64-apple-macosx10.6 -verify %s + +void f() { + thread_local int x; // expected-error {{thread-local storage is not supported for the current target}} +} |

