File: dllimport-constexpr.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (62 lines) | stat: -rw-r--r-- 2,207 bytes parent folder | download | duplicates (26)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// RUN: %clang_cc1 -std=c++14 %s -verify -fms-extensions -triple x86_64-windows-msvc
// RUN: %clang_cc1 -std=c++17 %s -verify -fms-extensions -triple x86_64-windows-msvc

__declspec(dllimport) void imported_func();
__declspec(dllimport) int imported_int;
struct Foo {
  void __declspec(dllimport) imported_method();
};

// Instantiation is OK.
template <void (*FP)()> struct TemplateFnPtr {
  static void getit() { FP(); }
};
template <void (&FP)()> struct TemplateFnRef {
  static void getit() { FP(); }
};
void instantiate1() {
  TemplateFnPtr<&imported_func>::getit();
  TemplateFnRef<imported_func>::getit();
}

// Check variable template instantiation.
template <int *GI> struct TemplateIntPtr {
  static int getit() { return *GI; }
};
template <int &GI> struct TemplateIntRef {
  static int getit() { return GI; }
};
int instantiate2() {
  int r = 0;
  r += TemplateIntPtr<&imported_int>::getit();
  r += TemplateIntRef<imported_int>::getit();
  return r;
}

// Member pointer instantiation.
template <void (Foo::*MP)()> struct TemplateMemPtr { };
TemplateMemPtr<&Foo::imported_method> instantiate_mp;

// constexpr initialization doesn't work for dllimport things.
// expected-error@+1{{must be initialized by a constant expression}}
constexpr void (*constexpr_import_func)() = &imported_func;
// expected-error@+1{{must be initialized by a constant expression}}
constexpr int *constexpr_import_int = &imported_int;
// expected-error@+1{{must be initialized by a constant expression}}
constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;

// We make dynamic initializers for 'const' globals, but not constexpr ones.
void (*const const_import_func)() = &imported_func;
int *const const_import_int = &imported_int;
void (Foo::*const const_memptr)() = &Foo::imported_method;

// Check that using a non-type template parameter for constexpr global
// initialization is correctly diagnosed during template instantiation.
template <void (*FP)()> struct StaticConstexpr {
  // expected-error@+1{{must be initialized by a constant expression}}
  static constexpr void (*g_fp)() = FP;
};
void instantiate3() {
  // expected-note@+1 {{requested here}}
  StaticConstexpr<imported_func>::g_fp();
}