aboutsummaryrefslogtreecommitdiff
path: root/clang/test/PCH
diff options
context:
space:
mode:
authorcor3ntin <corentinjabot@gmail.com>2023-11-30 08:45:05 +0100
committerGitHub <noreply@github.com>2023-11-30 08:45:05 +0100
commit030047c432cac133738be68fa0974f70e69dd58d (patch)
tree9e0e500d92fd0a6f05ab250c840fe2dedb0b5574 /clang/test/PCH
parent8a66510fa73c1507c2a58338e180ddb075993a5a (diff)
downloadllvm-030047c432cac133738be68fa0974f70e69dd58d.zip
llvm-030047c432cac133738be68fa0974f70e69dd58d.tar.gz
llvm-030047c432cac133738be68fa0974f70e69dd58d.tar.bz2
[Clang] Eagerly instantiate used constexpr function upon definition. (#73463)
Despite CWG2497 not being resolved, it is reasonable to expect the following code to compile (and which is supported by other compilers) ```cpp template<typename T> constexpr T f(); constexpr int g() { return f<int>(); } // #1 template<typename T> constexpr T f() { return 123; } int k[g()]; // #2 ``` To that end, we eagerly instantiate all referenced specializations of constexpr functions when they are defined. We maintain a map of (pattern, [instantiations]) independent of `PendingInstantiations` to avoid having to iterate that list after each function definition. We should apply the same logic to constexpr variables, but I wanted to keep the PR small. Fixes #73232
Diffstat (limited to 'clang/test/PCH')
-rw-r--r--clang/test/PCH/instantiate-used-constexpr-function.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/test/PCH/instantiate-used-constexpr-function.cpp b/clang/test/PCH/instantiate-used-constexpr-function.cpp
new file mode 100644
index 0000000..3930d04
--- /dev/null
+++ b/clang/test/PCH/instantiate-used-constexpr-function.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t
+// RUN: %clang_cc1 -std=c++2a -include-pch %t -verify %s
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+template<typename T> constexpr T f();
+constexpr int g() { return f<int>(); } // #1
+
+#else /*included pch*/
+
+template<typename T> constexpr T f() { return 123; }
+int k[g()];
+
+#endif // HEADER