[Clang] disallow use of attributes before extern template declarations (#136328)
Fixes #79893 --- This PR addresses the issue of _attributes_ being incorrectly allowed on `extern template` declarations ```cpp [[deprecated]] extern template struct S<int>; ```
This commit is contained in:
parent
1cb82ff9cd
commit
08b0c2517e
@ -301,6 +301,9 @@ related warnings within the method body.
|
||||
particularly relevant for AMDGPU targets, where they map to corresponding IR
|
||||
metadata.
|
||||
|
||||
- Clang now disallows the use of attributes applied before an
|
||||
``extern template`` declaration (#GH79893).
|
||||
|
||||
Improvements to Clang's diagnostics
|
||||
-----------------------------------
|
||||
|
||||
|
@ -1049,6 +1049,8 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
|
||||
|
||||
case tok::kw_extern:
|
||||
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {
|
||||
ProhibitAttributes(Attrs);
|
||||
ProhibitAttributes(DeclSpecAttrs);
|
||||
// Extern templates
|
||||
SourceLocation ExternLoc = ConsumeToken();
|
||||
SourceLocation TemplateLoc = ConsumeToken();
|
||||
|
8
clang/test/Parser/extern-template-attributes.cpp
Normal file
8
clang/test/Parser/extern-template-attributes.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// RUN: %clang_cc1 -std=c++17 -fms-extensions -verify %s
|
||||
|
||||
template <class>
|
||||
struct S {};
|
||||
|
||||
[[deprecated]] extern template struct S<int>; // expected-error {{an attribute list cannot appear here}}
|
||||
__attribute__((deprecated)) extern template struct S<int>; // expected-error {{an attribute list cannot appear here}}
|
||||
__declspec(deprecated) extern template struct S<int>; // expected-error {{expected unqualified-id}}
|
Loading…
x
Reference in New Issue
Block a user