Skip to content

Commit 08b0c25

Browse files
authored
[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>; ```
1 parent 1cb82ff commit 08b0c25

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ related warnings within the method body.
301301
particularly relevant for AMDGPU targets, where they map to corresponding IR
302302
metadata.
303303

304+
- Clang now disallows the use of attributes applied before an
305+
``extern template`` declaration (#GH79893).
306+
304307
Improvements to Clang's diagnostics
305308
-----------------------------------
306309

clang/lib/Parse/Parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,8 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
10491049

10501050
case tok::kw_extern:
10511051
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_template)) {
1052+
ProhibitAttributes(Attrs);
1053+
ProhibitAttributes(DeclSpecAttrs);
10521054
// Extern templates
10531055
SourceLocation ExternLoc = ConsumeToken();
10541056
SourceLocation TemplateLoc = ConsumeToken();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -std=c++17 -fms-extensions -verify %s
2+
3+
template <class>
4+
struct S {};
5+
6+
[[deprecated]] extern template struct S<int>; // expected-error {{an attribute list cannot appear here}}
7+
__attribute__((deprecated)) extern template struct S<int>; // expected-error {{an attribute list cannot appear here}}
8+
__declspec(deprecated) extern template struct S<int>; // expected-error {{expected unqualified-id}}

0 commit comments

Comments
 (0)