mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 21:56:04 +00:00

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
18 lines
357 B
C++
18 lines
357 B
C++
// 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
|