Debian Codegraph @

clang/test/Modules/pr62796.cppm

raw
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Cache.cppm -o %t/Cache.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fmodule-file=Fibonacci.Cache=%t/Cache.pcm \
7 // RUN: -fsyntax-only -verify
8
9 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/Cache.cppm -o %t/Cache.pcm
10 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fmodule-file=Fibonacci.Cache=%t/Cache.pcm \
11 // RUN: -fsyntax-only -verify
12
13 //--- Cache.cppm
14 export module Fibonacci.Cache;
15
16 export namespace Fibonacci
17 {
18 constexpr unsigned long Recursive(unsigned long n)
19 {
20 if (n == 0)
21 return 0;
22 if (n == 1)
23 return 1;
24 return Recursive(n - 2) + Recursive(n - 1);
25 }
26
27 template<unsigned long N>
28 struct Number{};
29
30 struct DefaultStrategy
31 {
32 constexpr unsigned long operator()(unsigned long n, auto... other) const
33 {
34 return (n + ... + other);
35 }
36 };
37
38 constexpr unsigned long Compute(Number<10ul>, auto strategy)
39 {
40 return strategy(Recursive(10ul));
41 }
42
43 template<unsigned long N, typename Strategy = DefaultStrategy>
44 constexpr unsigned long Cache = Compute(Number<N>{}, Strategy{});
45
46 template constexpr unsigned long Cache<10ul>;
47 }
48
49 //--- Use.cpp
50 // expected-no-diagnostics
51 import Fibonacci.Cache;
52
53 constexpr bool value = Fibonacci::Cache<10ul> == 55;
54
55 static_assert(value == true, "");