Skip to content

Commit 7344e99

Browse files
authored
[APINotes] Add test for C++ class templates
This upstreams swiftlang#7930. This adds a test to verify that we can apply attributes to C++ class templates using API Notes. Doing the same for function templates is not currently possible and requires more work.
1 parent 84299df commit 7344e99

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
Name: Templates
3+
Tags:
4+
- Name: Box
5+
SwiftImportAs: owned
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
template <typename T>
2+
struct Box {
3+
T value;
4+
5+
const T& get_value() const { return value; }
6+
const T* get_ptr() const { return &value; }
7+
};
8+
9+
using IntBox = Box<int>;

clang/test/APINotes/Inputs/Headers/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ module Namespaces {
3636
header "Namespaces.h"
3737
}
3838

39+
module Templates {
40+
header "Templates.h"
41+
}
42+
3943
module SwiftImportAs {
4044
header "SwiftImportAs.h"
4145
}

clang/test/APINotes/templates.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Tmpl -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -x c++
3+
// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Tmpl -fdisable-module-hash -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter Box -x c++ | FileCheck -check-prefix=CHECK-BOX %s
4+
5+
#include "Templates.h"
6+
7+
// CHECK-BOX: Dumping Box:
8+
// CHECK-BOX-NEXT: ClassTemplateDecl {{.+}} imported in Templates Box
9+
// CHECK-BOX: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned"

0 commit comments

Comments
 (0)