llvm-project/clang/test/SemaCXX/constexpr-late-instantiation.cpp
serge-sans-paille da6a14b91a [clang] Enforce instantiation of constexpr template functions during non-constexpr evaluation
Otherwise these functions are not instantiated and we end up with an undefined
symbol.

Fix #55560

Differential Revision: https://reviews.llvm.org/D128119
2022-07-10 08:40:03 +02:00

16 lines
461 B
C++

// RUN: %clang_cc1 %s -fsyntax-only -verify
template <typename T>
constexpr T foo(T a); // expected-note {{declared here}}
int main() {
int k = foo<int>(5); // Ok
constexpr int j = // expected-error {{constexpr variable 'j' must be initialized by a constant expression}}
foo<int>(5); // expected-note {{undefined function 'foo<int>' cannot be used in a constant expression}}
}
template <typename T>
constexpr T foo(T a) {
return a;
}