Author: Oleksandr T. Date: 2025-04-21T18:12:07+03:00 New Revision: 08b0c2517eb859667d59873bf04b6aa78a7583a7
URL: https://github.com/llvm/llvm-project/commit/08b0c2517eb859667d59873bf04b6aa78a7583a7 DIFF: https://github.com/llvm/llvm-project/commit/08b0c2517eb859667d59873bf04b6aa78a7583a7.diff LOG: [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>; ``` Added: clang/test/Parser/extern-template-attributes.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/Parser.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7417fdd71a392..36b528d9e20f8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ----------------------------------- diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index d528664bca352..a82aea162716a 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -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(); diff --git a/clang/test/Parser/extern-template-attributes.cpp b/clang/test/Parser/extern-template-attributes.cpp new file mode 100644 index 0000000000000..1301f2f680ccb --- /dev/null +++ b/clang/test/Parser/extern-template-attributes.cpp @@ -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}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits